What will be the output of the following C code?
#include <stdio.h>
typedef struct student
{
char *a;
}stu;
void main()
{
struct student s;
s.a = "hey";
printf("%s", s.a);
}
Answer: D
Correct answer: hey
Here the declaration uses the tag rather than the alias - struct student s; - and the tag student does exist, so this compiles. The member a is a char *, assigning a string literal to it is legal, and %s prints it: the output is hey. Compare the previous question, which used struct stu and failed for exactly this reason.
Please log in or register to report this question.