Basic Concept of Pointer : C Programming Language



A. Basic Concept of Pointer :

Pointer Concept in C Programming Language
Consider above Diagram :

  1. 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
  2. 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;

i.e

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 NameVariable ValueVariable Address
i565524
j6552465522

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;
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 :

  1. Pointer is a special variable which is capable of storing the Address of Ordinary Variable. i.e (integer,character,float)
  2. Pointer is Special Variable used to Reference and de-reference memory.
Data Type of Ordinary VariablePointer is called as
IntegerInteger Pointer
CharacterCharacter Pointer
DoubleDouble Pointer
FloatFloat Pointer

  1. When we declare integer pointer then we can only store address of integer variable into that pointer.
  2. 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.