+ 1
Can anyone please explain the working of below code snippet how pointer is pointing and printing the values.
#include<stdio.h> struct list { int a; char *ch; } s[] = {18, "GATE", 19, "CSE", 20, "COURSE"}; int main() { struct list *ptr = s; printf("%s\n", ptr++->ch); printf("%s\n", (++ptr)->ch); printf("%d\n", (--ptr)[1].a); printf("%d\n", ptr[0].a); return 0; }
1 Respuesta
+ 1
I tried my best explaining with comments in the code bit. But first you must know the following shorthands:
ptr->ch; is the same as: *(ptr).ch
(ptr++)->ch; is the same as: *(ptr).ch; ptr++;
ptr[1]; is the same as: *(ptr+1).a;
https://code.sololearn.com/cfG45zKw4GRP/?ref=app