C Questions and Answers Part-22

1. What will be the output of the following C code?
#include < stdio.h >
int x = 5;
void main()
{
int x = 3;
printf("%d", x);
{
int x = 4;
}
printf("%d", x);
}
a) 3 3
b) 3 4
c) 3 5
d) Run time error

Answer: a

2. Functions in C are always _________
a) Internal
b) External
c) Both Internal and External
d) External and Internal are not valid terms for functions

Answer: b

3. Global variables are ____________
a) Internal
b) External
c) Both Internal and External
d) None of the mentioned

Answer: b

4. Which of the following is an external variable in the following C code?
#include < stdio.h >
int func (int a)
{
int b;
return b;
}
int main()
{
int c;
func (c);
}
int d;
a) a
b) b
c) c
d) d

Answer: d

5. What will be the output of the following C code?
#include < stdio.h >
int main()
{
printf("%d", d++);
}
int d = 10;
a) 9
b) 10
c) 11
d) Compile time error

Answer: d

6. What will be the output of the following C code?
#include < stdio.h >
double var = 8;
int main()
{
int var = 5;
printf("%d", var);
}
a) 5
b) 8
c) Compile time error due to wrong format identifier for double
d) Compile time error due to redeclaration of variable with same name

Answer: a

7. What will be the output of the following C code?
#include < stdio.h >
int i;
int main()
{
extern int i;
if (i == 0)
printf("scope rules\n");
}
a) scope rules
b) Compile time error due to multiple declaration
c) Compile time error due to not defining type in statement extern i
d) Nothing will be printed as value of i is not zero because i is an automatic variable

Answer: a

8. What will be the output of the following C code (without linking the source file in which ary1 is defined)?
#include < stdio.h >
int main()
{
extern ary1[];
printf("scope rules\n");
}
a) scope rules
b) Linking error due to undefined reference
c) Compile time error because size of array is not provided
d) Compile time error because datatype of array is not provided

Answer: a

9. What will be the output of the following C code (after linking to source file having definition of ary1)?
#include < stdio.h >
int main()
{
extern ary1[];
printf("%d\n", ary1[0]);
}
a) Value of ary1[0];
b) Compile time error due to multiple definition
c) Compile time error because size of array is not provided
d) Compile time error because datatype of array is not provided

Answer: d

10. What is the scope of an external variable?
a) Whole source file in which it is defined
b) From the point of declaration to the end of the file in which it is defined
c) Any source file in a program
d) From the point of declaration to the end of the file being compiled

Answer: d