This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Macro Substitution – 1”.
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>
#define foo(m, n) m ## n
int main()
{
printf("%s\n", foo(k, l));
}
a) k l
b) kl
c) Compile time error
d) Undefined behaviour
View Answer
Explanation: None.
2. What will be the output of the following C code?
#include <stdio.h>
#define foo(m, n) " m ## n "
int main()
{
printf("%s\n", foo(k, l));
}
a) k l
b) kl
c) Compile time error
d) m ## n
View Answer
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
#define foo(x, y) #x #y
int main()
{
printf("%s\n", foo(k, l));
return 0;
}
a) kl
b) k l
c) xy
d) Compile time error
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
#define foo(x, y) x / y + x
int main()
{
int i = -6, j = 3;
printf("%d\n",foo(i + j, 3));
return 0;
}
a) Divided by zero exception
b) Compile time error
c) -8
d) -4
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
void f();
int main()
{
#define foo(x, y) x / y + x
f();
}
void f()
{
printf("%d\n", foo(-3, 3));
}
a) -8
b) -4
c) Compile time error
d) Undefined behaviour
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
void f();
int main()
{
#define max 10
f();
return 0;
}
void f()
{
printf("%d\n", max * 10);
}
a) 100
b) Compile time error since #define cannot be inside functions
c) Compile time error since max is not visible in f()
d) Undefined behaviour
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
#define foo(x, y) x / y + x
int main()
{
int i = -6, j = 3;
printf("%d ", foo(i + j, 3));
printf("%d\n", foo(-3, 3));
return 0;
}
a) -8 -4
b) -4 divided by zero exception
c) -4 -4
d) Divided by zero exception
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
int foo(int, int);
#define foo(x, y) x / y + x
int main()
{
int i = -6, j = 3;
printf("%d ",foo(i + j, 3));
#undef foo
printf("%d\n",foo(i + j, 3));
}
int foo(int x, int y)
{
return x / y + x;
}
a) -8 -4
b) Compile time error
c) -8 -8
d) Undefined behaviour
View Answer
Explanation: None.
9. What is the advantage of #define over const?
a) Data type is flexible
b) Can have a pointer
c) Reduction in the size of the program
d) None of the mentioned
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.
- Practice Computer Science MCQs
- Practice BCA MCQs
- Check C Books
- Watch Advanced C Programming Videos
- Check Computer Science Books