0

Which is used pointer in c program?

#include <stdio.h> int main() { int a[5] = {22, 33, 44, 55, 66}; int *ptr = NULL; ptr = a; /* point to the first array element */ printf("%d %x\n", *ptr, ptr); /* 22 */ ptr++; printf("%d %x\n", *ptr, ptr); /* 33 */ ptr += 3; printf("%d %x\n", *ptr, ptr); /* 66 */ ptr--; printf("%d %x\n", *ptr, ptr); /* 55 */ ptr -= 2; printf("%d %x\n", *ptr, ptr); /* 33 */ }

17th Sep 2020, 5:34 AM
Meet Sanghani
Meet Sanghani - avatar
2 odpowiedzi
+ 4
You created ptr pointer and value is null printf statement you printing value *(ptr +0 ) which represent first index of array so 22 will print and %x use for hex values and ptr printing address in hex form . After that ptr++ which increse the index same 33 will print and ptr for address .... 44 ... 66 and address. Hope you understood
17th Sep 2020, 6:10 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
I dont understand the question. Code seems to work as it should.
17th Sep 2020, 5:41 AM
arturop200
arturop200 - avatar