Solution
The correct answer is Nagpur Nagpur Nagpur
Key PointsIn C programming, a structure (struct) is a user-defined data type that groups related variables of different data types together. A struct is used for packaging data where each element, known as a member, can have a different type.
#include<stdio.h>
typedef struct s1 {
char * z;
int i;
struct s1 * p;
} s1;
int main() {
static s1 a[3] = {{"Nagpur", 1, a + 1}, {"Raipur", 2, a + 2}, {"Kanpur", 3, a}};
s1* ptr = a;
printf("%s %s %s\n", a[0].z, ptr -> z, a[2].p -> z);
return 0;
}
a[0].z refers to the string "Nagpur", which is the z value of the first structure.
ptr -> z also points to "Nagpur" because ptr was initialized to point to the first structure in the array.
a[2].p -> z also gives "Nagpur" because p of the third structure was initialized to point to the first structure in the array.
Therefore, the output of the corrected version of the provided code would be: Nagpur Nagpur Nagpur
This means the correct option from the given choices is 2) Nagpur Nagpur Nagpur.