Consider the following C program.
#include\(\lt\)stdio.h\(\gt\)
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:
GATE CS - 2018,
Answer: A
The program prints 0, c.
The structure holds three chars in order, x = '1', y = '0' and z = 'a'+2. Since 'a'+2 is evaluated as a character code, z holds 'c'. Casting q to char* and adding 1 and 2 points at y and z, so the two values printed are '0' and 'c'.
The format %c prints just the character, without quotes, so the options with quotes are wrong. 'a+2' would need the expression to be stored as text, but it is computed when the structure is initialised.
Please log in or register to report this question.