StreakPeaked· Practice

ExamsGATETechnical

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:

  1. 0,c
  2. 0,a+2
  3. '0','a+2'
  4. '0','c'

Correct answer: 0,c

Solution

The program initializes a struct with characters, where '1' is at index 0, '0' at index 1, and 'a'+2 evaluates to 'c' at index 2. The pointer arithmetic used in the printf statement accesses the second and third characters of the struct, resulting in '0' and 'c' being printed.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →