Professional Documents
Culture Documents
Presentation On Pointer
Presentation On Pointer
ON
INTRODUCTION TO POINTER IN C
location for the integer variable number and puts Number — Variable
the value 179 in that location. Let’s assume that 179 — Value
5000 — Address
the system has chosen the address location 5000
for number. Fig-1: Understanding pointers
Pointers are built on three concepts. They are:
1.Pointer constants : Pointer constants cannot be changed, we can only use them to
store data value.
2. Pointer values : The pointer value (the address of a variable) may change from
one run of the program to another.
3. Pointer variables : The variable that contains a pointer value is called a pointer
variables.
Accessing the address of a variable :
Let us assume a problem that given below: In this program, this
is seen that the
#include <stdio.h> address of x is
void main() given by &x.
{ The & operator can
int x = 125; be remembered as
printf(“%d is stored at address %u.\n”, x, &x); ‘address of’.
}
Output:
125 is stored at address 4434.
Declaring pointer variables:
In C, every variable must be declared for its type. The declaration of a
pointer variable take the following form:
data_type *pt_name;
This tells the compiler three things about the variable pt_name. They are:
• The asterisk (*) tells the variable pt_name.
• pt_name needs a memory location.
• pt_name points to a variable of data_type.
For example:
int *p;/*integer pointer*/
Declare the variable p as a pointer variable that points to an integer data
type.
Pointer declaration style:
int* p;
int *p;
int * p;
Let’s see a pointer code:
#include <stdio.h>
int main()
{
int *ptr, q;
q = 50;
ptr = &q;
printf("%d is in %u", q, ptr);
return 0;
}
Output :
50 is in 6356744