Pointer Assignment Operations in C
Notes:
Pointer Assignment Operations in C Programming Language:
- Pointer is a variable; which holds the address of another memory location; and address of another memory location is just a numeric value
The valid operations; that can be performed on a pointer are:
1. Assignment operations
2. Increment and decrement operations
3. Addition and subtraction operations
4. Comparison operations
1. Assignment Operations:
- A pointer variable can be assigned with the address of another memory location or NULL
- If 2 pointer variables are of same type, then they can be assigned to one another
Example Code:
#include <stdio.h>
int main()
{
int num = 10;
int *iptr1 = NULL;
int *iptr2 = NULL;
iptr1 = #
printf("Value of num using num=%d\n",num); // Value of num using num=10
printf("Value of num using iptr1=%d\n",*iptr1);// Value of num using iptr1=10
printf("\n");
*iptr1 = 20;
printf("Value of num using num=%d\n",num); // Value of num using num=20
printf("Value of num using iptr1=%d\n",*iptr1);// Value of num using iptr1=20
printf("\n");
iptr2 = iptr1;
printf("Value of num using num=%d\n",num); // Value of num using num=20
printf("Value of num using iptr1=%d\n",*iptr1);// Value of num using iptr1=20
printf("Value of num using iptr2=%d\n",*iptr2);// Value of num using iptr2=20
printf("\n");
*iptr2 = 30;
printf("Value of num using num=%d\n",num); // Value of num using num=30
printf("Value of num using iptr1=%d\n",*iptr1);// Value of num using iptr1=30
printf("Value of num using iptr2=%d\n",*iptr2);// Value of num using iptr2=30
printf("\n");
return 0;
}