GATE 2018 CS – Question 12
Consider the following C program.
#include<stdio.h>
struct Ournode{
char x,y,z;
};
int main(){
struct Ournode p = {'1', '0', 'a'+2};
struct Ournode *q = &p;
printf ("%c, %c", *((char*)q+1), *((char*)q+2));
return 0;
}The output of this program is:
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (A) 0, c
Explanation
The three chars are stored consecutively: `x='1'`, `y='0'`, `z='c'`. `(char*)q+1` is `y` and `(char*)q+2` is `z`, so it prints `0, c` (printf with `%c` does not print quotes).