The Wayback Machine - https://web.archive.org/web/20230527151558/https://www.geeksforgeeks.org/gate-gate-cs-2018-question-33/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

GATE | GATE CS 2018 | Question 33

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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:

(A) 0, c
(B) 0, a+2
(C) ‘0’, ‘a+2’
(D) ‘0’, ‘c’


Answer: (A)

Explanation: ‘a’ + 2 will be ‘c’, so Ournode p = {‘1’, ‘0’, ‘c’} and output will be 0, c.

See: storage for Strings in C, string.

Option (A) is correct.



Quiz of this Question

My Personal Notes arrow_drop_up
Last Updated : 12 Aug, 2021
Like Article
Save Article
Similar Reads