A. Basic Concept of Pointer :
- i is the name given for Particular memory location , Let it’s Corresponding address be 65624 and the Value stored in variable ‘i’ is 5
- The address of the variable ‘i’ is stored in another integer variable whose name is ‘j’ and which is having 65522 as its corresponding address .
thus we can say that -
j = &i;
j = Address of i
Here j is not ordinary variable , It is special variable and called pointer variable as it stores the address of the another ordinary variable
B. In short we can summarize it as -
|Variable Name||Variable Value||Variable Address|
C. Important Pointer Declaration Tips :
1. Pointer is declared with preceding * :
int *ptr; //Here ptr is Integer Pointer Variable
int ptr; //Here ptr is Normal Integer Variable
2. Whitespace while Writing Pointer :
pointer variable name and asterisk can contain whitespace because whitespace is ignored by compiler.
int * ptr;
int * ptr;
All the above syntax are legal and valid. We can insert any number of spaces or blanks inside declaration. We can also split the declaration on multiple lines.
D. Pointer Summary :
- Pointer is a special variable which is capable of storing the Address of Ordinary Variable. i.e (integer,character,float)
- Pointer is Special Variable used to Reference and de-reference memory.
|Data Type of Ordinary Variable||Pointer is called as|
- When we declare integer pointer then we can only store address of integer variable into that pointer.
- Similarly if we declare character pointer then only the address of character variable is stored into the pointer variable.
You will be more familiar with pointer in the next chapter – Understanding Pointer Concept in C Programming.