in Technology by
How is a Program increment a pointer in C?

1 Answer

0 votes
by

In the below program, I am creating a character and float pointer and incrementing the pointer by 1 using the increment operator. After performing the arithmetic operation on pointer I am printing the address which is pointing by pointers.

#include <stdio.h>
#include <stdlib.h>
int main()
{
char *pcData = NULL; //pointer to character
float *pfData = NULL; // pointer to float
printf(" Address of character pointer before incrementation = %d\n\n\n", pcData);
printf(" Address of float pointer before incrementation = %d\n\n\n", pfData);
pcData++; //Increment the character pointer by one
pfData++; //Increment the float pointer by one
printf(" Address of character pointer After incrementation = %d\n\n\n", pcData);
printf(" Address of float pointer After incrementation = %d\n\n\n", pfData);
return 0;
}

Output:

pointer arithmetic

 

 

 

 

 

 

 

#include <stdio.h>
#include <stdlib.h>
int main()
{
char *pcData = NULL; //pointer to character
float *pfData = NULL; // pointer to float
printf("\n\n Address of character pointer before incrementation = %d\n\n\n", pcData);
printf(" Address of float pointer before incrementation = %d\n\n\n", pfData);
pcData = pcData + 2; //Increment the character pointer by one
pfData = pfData + 2; //Increment the float pointer by one
printf(" Address of character pointer After incrementation = %d\n\n\n", pcData);
printf(" Address of float pointer After incrementation = %d\n\n\n", pfData);
return 0;
}

 

 

 

 

Related questions

0 votes
    What is Indirection and Increment/Decrement operators with a pointer in C?...
asked Jan 24, 2021 in Technology by JackTerrance
0 votes
    What is the process to create increment and decrement statement in C?...
asked Nov 8, 2020 in Technology by JackTerrance
0 votes
    How can we do Pointer comparison in C?...
asked Jan 24, 2021 in Technology by JackTerrance
0 votes
    How to declare a pointer to a function in C?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    Which type of pointer is the most convenient way of storing the raw address in C programming?...
asked Jan 23, 2021 in Technology by JackTerrance
0 votes
    What is the use of a double pointer (pointer to pointer) in C?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    What is the advantage of a void pointer in C?...
asked Jan 22, 2021 in Technology by JackTerrance
0 votes
    What is the usage of the NULL pointer in C?...
asked Jan 21, 2021 in Technology by JackTerrance
0 votes
    What is the size of a void pointer in C?...
asked Jan 21, 2021 in Technology by JackTerrance
0 votes
    What is a near pointer in C?...
asked Jan 21, 2021 in Technology by JackTerrance
0 votes
    What is a far pointer in C?...
asked Jan 21, 2021 in Technology by JackTerrance
0 votes
    What is the usage of the pointer in C?...
asked Jan 21, 2021 in Technology by JackTerrance
0 votes
    What is dangling pointer in C?...
asked Jan 21, 2021 in Technology by JackTerrance
0 votes
    What is a constant pointer in C?...
asked Nov 9, 2020 in Technology by JackTerrance
+1 vote
    Which operator can be used to access union elements if union variable is a pointer variable in C Programming ?...
asked Nov 9, 2020 in Technology by JackTerrance
...