This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Basics of Functions – 2”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include <stdio.h>
int main()
{
void foo();
printf("1 ");
foo();
}
void foo()
{
printf("2 ");
}
a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}
a) Compile time error as foo is local to main
b) 1 2
c) 2 1
d) Compile time error due to declaration of functions inside main
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
int main()
{
void foo();
void f()
{
foo();
}
f();
}
void foo()
{
printf("2 ");
}
a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler
View Answer
Explanation: Even though the answer is 2, this code will compile fine only with gcc. GNU C supports nesting of functions in C as a language extension whereas standard C compiler doesn’t.
4. What will be the output of the following C code?
#include <stdio.h>
void foo();
int main()
{
void foo();
foo();
return 0;
}
void foo()
{
printf("2 ");
}
a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
void foo();
int main()
{
void foo(int);
foo(1);
return 0;
}
void foo(int i)
{
printf("2 ");
}
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
void foo();
int main()
{
void foo(int);
foo();
return 0;
}
void foo()
{
printf("2 ");
}
a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
void m()
{
printf("hi");
}
void main()
{
m();
}
a) hi
b) Run time error
c) Nothing
d) Varies
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
void m();
void n()
{
m();
}
void main()
{
void m()
{
printf("hi");
}
}
a) hi
b) Compile time error
c) Nothing
d) Varies
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check C Books
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Apply for C Internship
- Watch Advanced C Programming Videos