Computer StudyMCQ Computer ScienceQuiz Computer ScienceUGC NET

C Programming Questions and Answers – Macro Substitution

C Programming Questions and Answers – Macro Substitution

1. What is the output of this C code?

#include
#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

Answer:c

2. What is the output of this C code?

#include
#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

Answer:d

3. What is the output of this C code?

#include
#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

Answer:a

4. What is the output of this C code?

#include
#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

Answer:c

5. What is the output of this C code?

#include
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

Answer:b

6. What is the output of this C code?

#include
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

Answer:a

7. What is the output of this C code?

#include
#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

Answer:a

8. What is the output of this C code?

#include
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

Answer:a

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) Both (a) and (c)

View Answer

Answer:a

10. What is the output of this C code?

#include
void main()
{
#define max 37;
printf(“%d”, max);
}
a) 37
b) Compile time error
c) Varies
d) Depends on compiler

View Answer

Answer:b

11. What is the output of this C code?

#include
void main()
{
#define max 37
printf(“%d”, max);
}
a) 37
b) Run time error
c) Varies
d) Depends on compiler

View Answer

Answer:a

12. What is the output of this C code?

#include
void main()
{
#define const int
const max = 32;
printf(“%d”, max);
}
a) Run time error
b) 32
c) int
d) const

View Answer

Answer:b

13. What is the output of this C code?

#include
void main()
{
#define max 45
max = 32;
printf(“%d”, max);
}
a) 32
b) 45
c) Compile time error
d) Varies

View Answer

Answer:c

14. What is the output of this C code?

#include
# define max
void m()
{
printf(“hi”);
}
void main()
{
max;
m();
}
a) Run time error
b) hi hi
c) Nothing
d) hi

View Answer

Answer:d

15. What is the output of this C code?

#include
#define A 1 + 2
#define B 3 + 4
int main()
{
int var = A * B;
printf(“%d\n”, var);
}
a) 9
b) 11
c) 12
d) 21

View Answer

Answer:b

16. 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

View Answer

Answer:d

17. Comment on the following code?

#include
#define var 20);
int main()
{
printf(“%d\n”, 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) Both (b) and (c).

View Answer

Answer:a

18. Which of the following properties of #define 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

View Answer

Answer:d

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button