Home
MCQS
C/C MCQ Quiz Hub
C Multiple Choice Questions C Functions Set 1
Choose a topic to test your knowledge and improve your C/C skills
1. What is the output of this C code? int main() { void foo(), f(); f(); } void foo() { printf("2 "); } void f() { printf("1 "); foo(); }
Compile time error as foo is local to main
1 2
2 1
Compile time error due to declaration of functions inside main
2. What is the output of this C code? int main() { void foo(); void f() { foo(); } f(); } void foo() { printf("2 "); }
2 2
2
Compile time error
Depends on the compiler
3. What is the output of this C code? void foo(); int main() { void foo(); foo(); return 0; } void foo() { printf("2 "); }
Compile time error
2
Depends on the compiler
Depends on the standard
4. What is the output of this C code? void foo(); int main() { void foo(int); foo(1); return 0; } void foo(int i) { printf("2 "); }
2
Compile time error
Depends on the compiler
Depends on the standard
5. What is the output of this C code? void m() { printf("hi"); } void main() { m(); }
hi
Run time error
Nothing
Varies
6. What is the output of this C code? void m() { printf("hi"); } void main() { m(); }
hi
Run time error
Nothing
Varies
7. What is the output of this C code? void m(); void n() { m(); } void main() { void m() { printf("hi"); } }
hi
Compile time error
Nothing
Varies
8. What is the output of this C code? void main() { m(); void m() { printf("hi"); } }
hi
Compile time error
Nothing
Varies
9. What is the output of this C code? void main() { m(); } void m() { printf("hi"); m(); }
Compile time error
hi
Infinite hi
Nothing
10. What is the output of this C code? void main() { static int x = 3; x++; if (x <= 5) { printf("hi"); main(); } }
Run time error
hi
infinite hi
hi hi
11. Which of the following function declaration is illegal?
int 1bhk(int);
int 1bhk(int a);
int 2bhk(int*, int []);
All of the mentioned
12. Which function definition will run correctly?
int sum(int a, int b) return (a + b);
int sum(int a, int b) {return (a + b);}
int sum(a, b) return (a + b);
Both (a) and (b)
13. Can we use a function as a parameter of another function? [ Eg: void wow(int func()) ]
Yes, and we can use the function value conveniently
Yes, but we call the function again to get the value, not as convenient as in using variable
No, C does not support it
This case is compiler dependent
14. The value obtained in the function is given back to main by using ________ keyword?
return
static
new
volatile
15. What is the return-type of the function sqrt()
int
float
double
Depends on the data type of the parameter
16. Which of the following function declaration is illegal?
double func(); int main(){} double func(){}
double func(){}; int main(){}
int main() { double func(); } double func(){//statements}
None of the mentioned
17. What is the output of this code having void return-type function? void foo() { return 1; } void main() { int x = 0; x = foo(); printf("%d", x); }
1
2
Runtime error
Compile time error
18. What will be the data type returned for the following function? int func() { return (double)(char)5.0; }
char
int
double
multiple type-casting in return is illegal
19. What is the problem in the following declarations? int func(int); double func(int); int func(float);
A function with same name cannot have different signatures
A function with same name cannot have different return types
A function with same name cannot have different number of parameters
All of the mentioned
20. The output of the code below is void main() { int k = m(); printf("%d", k); } void m() { printf("hello"); }
hello5
Error
Nothing
Junk value
21. The output of the code below is int *m() { int *p = 5; return p; } void main() { int *k = m(); printf("%d", k); }
1
Junk value
0
5
22. The output of the code below is int *m(); void main() { int *k = m(); printf("hello "); printf("%d", k[0]); } int *m() { int a[2] = {5, 8}; return a; }
hello 5 8
hello 5
hello followed by garbage value
Compilation error
23. The output of the code below is int *m(); void main() { int k = m(); printf("%d", k); } int *m() { int a[2] = {5, 8}; return a; }
5
8
Nothing
Varies
24. The output of the code below is void m(int k) { printf("hi"); } void m(double k) { printf("hello"); } void main() { m(3); }
hi
hello
hi
Nothing
25. What is the default return type if it is not specified in function definition?
void
int
double
short int
26. What is the output of this C code? int foo(); int main() { int i = foo(); } foo() { printf("2 "); return 2; }
1
Compile time error
Depends on the compiler
Depends on the standard
27. What is the output of this C code? double foo(); int main() { foo(); return 0; } foo() { printf("2 "); return 2; }
2
Compile time error
Depends on the compiler
Depends on the standard
28. functions can return structure in c?
True
False
Depends on the compiler
Depends on the standard
29. functions can return enumeration constants in c?
True
False
depends on the compiler
depends on the standard
30. What is the output of this C code? void main() { m(); printf("%d", x); } int x; void m() { x = 4; }
4
Compile time error
0
Undefined
31. What is the output of this C code? int x; void main() { printf("%d", x); }
Junk value
Run time error
0
Undefined
32. What is the output of this C code? int x = 5; void main() { int x = 3; printf("%d", x); { x = 4; } printf("%d", x); }
Run time error
3
3 5
3 4
33. What is the output of this C code? int x = 5; void main() { int x = 3; printf("%d", x); { int x = 4; } printf("%d", x); }
3 3
3 4
3 5
Run time error
34. Functions in C are ALWAYS:
Internal
External
Both Internal and External
External and Internal are not valid terms for functions
35. Which of the following are an external variable? int func (int a) { int b; return b; } int main() { int c; func (c); } int d;
a
b
c
d
36. What will be the output? int main() { printf("%d", d++); } int d = 10;
9
10
11
Compile time error
37. What will be the output? double var = 8; int main() { int var = 5; printf("%d", var); }
5
8
Compile time error due to wrong format identifier for double
ompile time error due to redeclaration of variable with same name
38. What is the output of this C code? double i; int main() { printf("%g ",i); return 0; }
0
0.000000
Garbage value
Depends on the compiler
39. Which part of the program address space is p stored in the code given below? int *p; int main() { int i = 0; p = &i; return 0; }
Code/text segment
Data segment
Bss segment
Stack
40. Can variable i be accessed by functions in another source file? int i; int main() { printf("%d ", i); }
0
false
Only if static keyword is used
Depends on the type of the variable
41. Property of external variable to be accessed by any source file is called by C90 standard as:
external linkage
external scope
global scope
global linkage
42. What is the output of this C code? int *i; int main() { if (i == NULL) printf("true "); return 0; }
true
true only if NULL value is 0
Compile time error
Nothing
43. What is the output of this C code? int *i; int main() { if (i == 0) printf("true "); return 0; }
true
true only if NULL value is 0
Compile time error
Nothing
44. What is the output of this C code? static int x = 5; void main() { x = 9; { int x = 4; } printf("%d", x); }
9
4
5
0
45. What is the output of this C code? void main() { m(); m(); } void m() { static int x = 5; x++; printf("%d", x); }
6 7
6 6
5 5
5 6
46. What is the output of this C code? void main() { static int x; printf("x is %d", x); }
0
1
Junk value
Run time error
47. What is the output of this C code? static int x; void main() { int x; printf("x is %d", x);
0
Junk value
Run time error
Nothing
48. What is the output of this C code? void main() { static double x; int x; printf("x is %d", x); }
0
Nothing
Compile time error
Junk value
49. What is the output of this C code? void main() { static int x; if (x++ < 2) main(); }
Infinite calls to main
Run time error
Varie
main is called twice
50. Which of following is not accepted in C?
static a = 10; //static as
static int func (int); //parameter as static
static static int a; //a static variable prefixed with static
All of the mentioned
51. Which of the following cannot be static in C?
Variables
Functions
Structures
None of the mentioned
52. The scope of an automatic variable is:
Within the block it appears
Within the blocks of the block it appears
Until the end of program
Both (a) and (b)
53. Automatic variables are allocated space in the form of a:
stack
queue
priority
random
54. Which of the following is a storage specifier?
enum
union
auto
volatile
55. Default storage class if not any is specified for a local variable, is auto:
true
false
Depends on the standard
None of the mentioned
56. Automatic variables are stored in:
stack
data segment
register
heap
57. What linkage does automatic variables have?
Internal linkage
External linkage
No linkage
None of the mentioned
58. What is the output of this C code? int main() { auto i = 10; const auto int *p = &i; printf("%d ", i); }
10
Compile time error
Depends on the standard
Depends on the compiler
Submit