code :
#include <stdio.h>
struct test {
int i;
char *c;
}st[] = {5, "become", 4, "better", 6, "jungle", 8, "ancestor", 7, "brother"};
int main () {
//printf("size = %d\n",sizeof(struct test) );
struct test *p = st;
p += 1;
++p->c; // ++(p->c)
printf("%s,", p++->c); // (p++)->c
printf("%c,", *++p->c); // *(++(p->c))
printf("%d,", p[0].i);
printf("%s \n", p->c);
}
We will assume few things:
- Size of integer $4$ Bytes.
- Size of a pointer $4$ Bytes.
Neglecting any alignment issues with the storage of this structure we will have $8$ Bytes per structure.
And one precedence rule we need to use:
Initial situation :
struct test *p = st;
p += 1;
We know that if ptr
is a pointer then, ptr + x = ptr + x*sizeof(*ptr);
++p->c;
printf("%s,", p++->c); // (p++)->c
printf("%c,", *++p->c); // *(++(p->c))
printf("%d,", p[0].i);
printf("%s \n", p->c);
Correct Answer: $B$