Pointer increment / decrement:
- We use modify operators to increase or decrease the value of a variable by one.
- Increment operators increase the value by 1.
- Decrement operators decrease the value by 1
#include<stdio.h>
int main()
{
int x=10, y=20;
printf("x value : %d \n", x);
printf("++x value : %d \n", ++x);
printf("y value : %d \n", y);
printf("--y value : %d \n", --y);
return 0;
}
- When we modify a pointer variable, it is increased by size bytes.
- Char* modifies by 1 byte
- Float* modifies by 4 bytes…
#include<stdio.h>
int main()
{
char x = 'a';
float y = 2.3;
double z = 4.5;
char* p1 = &x;
float* p2 = &y;
double* p3 = &z;
printf("p1 value is : %u \n", p1);
printf("++p1 value is : %u \n", ++p1);
printf("p2 value is : %u \n", p2);
printf("++p2 value is : %u \n", ++p2);
printf("p3 value is : %u \n", p3);
printf("++p3 value is : %u \n", ++p3);
return 0;
}