×
☰ Menu

Pointer Operations

Pointers can be used for arithmetic and other operations just like regular variables. The four types of operations that can be carried out on pointers are as follows.

  1. Pointer assignments
  2. Pointer conversion
  3. Pointer arithmetic
  4. Pointer comparison
  5. Pointer expression

 


 

Pointer Assignments

When two pointers are assigned to each other, they both point to the same variable. So the assignment y = x; makes y point to the same variable as x. The variables are unaffected by pointer assignment. It only modifies one pointer such that it shares the same reference as another. After the pointer assignment, the two pointers are said to be "sharing" the variable.

This is presented below:

void main ( )
{
int n=10; *p, *q;
p=&n;
q=p;
printf(“%d%d%d”,n, *p, *q);
printf(“%p%p%p”,&n, p, p);
}

 

 

Pointer conversion

 

Pointer arithmetic

 

Pointer comparison

 

Pointer expression