What will be the output of the following C code?
#include <stdio.h>
typedef struct p
{
int x, y;
}k = {1, 2};
int main()
{
p k1 = k;
printf("%d\n", k1.x);
}
Answer: A
Correct answer: Compile time error
Because the declaration begins with typedef, the k after the closing brace is a type name, and a type name cannot be given an initialiser - = {1, 2} is meaningless there. The later p k1 = k; compounds the error by using the tag p as a type. Remove the typedef and k becomes an initialised variable.
Please log in or register to report this question.