C Programming Questions and Answers – Macro Substitution – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Macro Substitution – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

1. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         #define max 37;
  5.         printf("%d", max);
  6.     }

a) 37
b) Compile time error
c) Varies
d) Depends on compiler
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

2. What will be the output of the following C code?

advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         #define max 37
  5.         printf("%d", max);
  6.     }

a) 37
b) Run time error
c) Varies
d) Depends on compiler
View Answer

Answer: a
Explanation: None.
advertisement

3. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         #define const int
  5.         const max = 32;
  6.         printf("%d", max);
  7.     }

a) Run time error
b) 32
c) int
d) const
View Answer

Answer: b
Explanation: None.
advertisement

4. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         #define max 45
  5.         max = 32;
  6.         printf("%d", max);
  7.     }

a) 32
b) 45
c) Compile time error
d) Varies
View Answer

Answer: c
Explanation: None.

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     # define max
  3.     void m()
  4.     {
  5.         printf("hi");
  6.     }
  7.     void main()
  8.     {
  9.         max;
  10.         m();
  11.     }

a) Run time error
b) hi hi
c) Nothing
d) hi
View Answer

Answer: d
Explanation: None.

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     #define A 1 + 2
  3.     #define B 3 + 4
  4.     int main()
  5.     {
  6.         int var = A * B;
  7.         printf("%d\n", var);
  8.     }

a) 9
b) 11
c) 12
d) 21
View Answer

Answer: b
Explanation: 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
View Answer

Answer: d
Explanation: None.

8. Comment on the output of the following C code.

  1.     #include <stdio.h>
  2.     #define var 20);
  3.     int main()
  4.     {
  5.         printf("%d\n", var
  6.     }

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.