What is the output of the following code?main() {
struct s1 { char *z; int i; struct s1 *p; };
static struct s1 a[] = {
{"Nagpur", 1, a+1},
{"Raipur", 2, a+2},
{"Kanpur", 3, a}
};
struct s1 *ptr = a;
printf("%s %s %s\n", a[0].z, ptr->z, a[2].p->z);
}
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. Nagpur Nagpur Nagpur
Explanation
a[0].z is 'Nagpur'. ptr points to a[0], so ptr->z is 'Nagpur'. a[2].p points back to a, so a[2].p->z is also 'Nagpur'.More Programming Languages and Computer Graphics questions
- The Sutherland-Hodgeman method is used on
- What is x in the following program?#include <stdio.h> int main() { typedef int (*(*arrfptr[3])())[10]; arrfptr x; return 0; }
- How will you free the memory allocated by the following program?#include <stdio.h> #include <stdlib.h> #define MAXROW 3 #define MAXCOL 4 in…
- The clipping process in computer graphics is used for
- Consider the rectangle with vertices (0, 0), (0, 2), (3, 0), (3, 2). It is scaled by 2 along the x-axis and 3 along the y-axis. The new coo…
- Which of the following 2-D transformations is used to resize a 2-dimensional object?