Skip to content

UGC NET CS 2023Programming Languages and Computer Graphics › Programming in CVerified

UGC NET CS 2023 PYQ: What is the output of following code? main () struct s1 { char * z; int i; struct s1 * p; } static struct s…

What is the output of following code?

main ()
struct s1
{ char * z;
int i;
struct s1 * p;
}
static struct s 1 a []}={
    {"Nagpur", 1, a+1}
{"Raipur', 2, a+2}
{"Kanpur', 3, a}
};
struct s 1* ptr =a;
printf (%s %s %s\n", a[0].z. ptr $/rightarrow$ z, a [2]. p $/rightarrow$ z;)
  1. A
    Nagpur Raipur Kanpur
  2. B
    Nagpur Nagpur Nagpur
    Correct answer
  3. C
    Kanpur Kanpur Kanpur
  4. D
    Error

Answer

(B) Nagpur Nagpur Nagpur

Approach

Trace the struct array initialisation and the pointer links.

Reviewed by UGC IQ Editorial Team.