Here is a listing of C programming questions on “Macro Substitution” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include -
void main()
-
{ -
#define max 37; -
printf("%d", max);
-
}
a) 37
b) Compile time error
c) Varies
d) Depends on compiler
Answer: b
Clarification: None.
2. What will be the output of the following C code?
-
#include -
void main()
-
{ -
#define max 37 -
printf("%d", max);
-
}
a) 37
b) Run time error
c) Varies
d) Depends on compiler
Answer: a
Clarification: None.
3. What will be the output of the following C code?
-
#include -
void main()
-
{ -
#define const int -
const max = 32;
-
printf("%d", max);
-
}
a) Run time error
b) 32
c) int
d) const
Answer: b
Clarification: None.
4. What will be the output of the following C code?
-
#include -
void main()
-
{ -
#define max 45 -
max = 32;
-
printf("%d", max);
-
}
a) 32
b) 45
c) Compile time error
d) Varies
Answer: c
Clarification: None.
5. What will be the output of the following C code?
-
#include -
# define max -
void m()
-
{ -
printf("hi");
-
} -
void main()
-
{ -
max; -
m();
-
}
a) Run time error
b) hi hi
c) Nothing
d) hi
Answer: d
Clarification: None.
6. What will be the output of the following C code?
-
#include -
#define A 1 + 2 -
#define B 3 + 4 -
int main()
-
{ -
int var = A * B;
-
printf("%dn", var);
-
}
a) 9
b) 11
c) 12
d) 21
Answer: b
Clarification: None.
7. Which of the following Macro substitution are accepted in C?
a)
#define A #define A VAR 20
b)
#define A define #A VAR 20
c)
#define #A #define #A VAR 20
d) None of the mentioned
Answer: d
Clarification: None.
8. Comment on the output of the following C code.
-
#include -
#define var 20); -
int main()
-
{ -
printf("%dn", var
-
}
a) No errors, it will show the output 20
b) Compile time error, the printf braces aren’t closed
c) Compile time error, there are no open braces in #define
d) None of the mentioned
Answer: a
Clarification: None.
9. Which of the following properties of #define is not true?
a) You can use a pointer to #define
b) #define can be made externally available
c) They obey scope rules
d) All of the mentioned
Answer: d
Clarification: None.
