C Programming and Technical

output?
Q.
main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}

A. Linker error: undefined symbol '_i'.

Explanation: extern declaration specifies that the variable i is defined somewhere else. The
compiler passes the external variable to be resolved by the linker. So compiler doesn't find an
error. During linking the linker searches for the definition of i. Since it is not found the linker flags
an error.

Read Solution (Total 0)

C Other Question

output??
Q.
#include
main()
{
struct xx
{i
nt x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}

A. Compiler Error

Explanation: Initialization should not be done for structure members inside the structure
declaration
Q. main()
{
printf("%d", out);
}i
nt out=100;

A. Compiler error: undefined symbol out in function main.

Explanation: The rule is that a variable is available for use from the point of declaration. Even
though a is a global variable, it is not available for main. Hence an error.