C Programming and Technical

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.

Read Solution (Total 0)

C Other Question

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.
Q. main()
{
show();
}
void show()
{
printf("I'm the greatest");
}

A. Compier error: Type mismatch in redeclaration of show.

Explanation: When the compiler sees the function show it doesn't know anything about it. So
the default return type (ie, int) is assumed. But when compiler sees the actual definition of show
mismatch occurs since it is declared as void. Hence the error.
The solutions are as follows:
1. declare void show() in main() .
2. define show() before main().
3. declare extern void show() before the use of show().