logo
  • Home
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

C++ Multiple Choice Questions | MCQs | Quiz

C++ Interview Questions and Answers
Pratice C++ questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Types
•   Booleans
•   Character Types
•   Integer Types
•   Floating Point Types
•   Sizes
•   Void
•   Enumerations
•   Declaration
•   Pointers
•   Arrays
•   Pointers into Arrays
•   Constants
•   References
•   Pointer to Void
•   Structures
•   Operators
•   Statements
•   Comments & Indentation
•   Function Declarations
•   Argument Passing
•   Value Return
•   Overloaded Function
•   Default Arguments
•   Unspecified Arguments
•   Pointer to Function
•   Macros
•   Modularization
•   Namespaces
•   Exceptions
•   Linkage
•   Header Files Usage
•   Classes
•   User Defined Types
•   Objects
•   Operator Functions
•   Complex Number Type
•   Conversion Operators
•   Friends
•   Large Objects
•   Essential Operators
•   Subscripting
•   Function Call
•   Dereferencing
•   Increment & Decrement
•   String Class
•   Derived Classes
•   Abstract Classes
•   Class Hierarchies
•   Abstract Classes
•   Simple String Template
•   Function Templates
•   Policy Usage Template
•   Specialization
•   Derivation & Templates
•   Error Handling
•   Grouping of Exceptions
•   Catching Exceptions
•   Resource Management
•   Exceptions Not Errors
•   Exception Specifications
•   Uncaught Exceptions
•   Exceptions & Efficiency
•   Error Handling Alternatives
•   Standard Exceptions
•   Class Hierarchies
•   Multiple Inheritance
•   Access Control
•   Run Time Type
•   Pointers to Members
•   Free Store
•   Standard Library Design
•   Container Design
•   Vector
•   Sequences
•   Sequence Adapters
•   Associative Containers
•   Almost Containers
•   Defining a New Container
•   Library Algorithms
•   Sequences / Containers
•   Function Objects
•   Nonmodifying Algorithms
•   Modifying Algorithms
•   Stored Sequences
•   Heaps
•   Min and Max
•   Permutations
•   C Style Algorithms
•   Iterators & Sequences
•   Checked Iterators
•   Allocators
•   String Characters
•   Basic String
•   C Standard Library
•   Output Stream
•   Input Stream
•   Formatting
•   File & String Streams
•   Buffering
•   Locale
•   C Input Output
•   Numeric Limits
•   Mathematical Functions
•   Vector Arithmetic
•   Numeric Algorithms
•   Random Numbers

Best Reference Books

C++ Books
« Prev Page
Next Page »

C++ Programming Questions and Answers – Macros

Posted on November 13, 2012 by Manish
This section on C++ interview questions and answers focuses on “Macros”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ interview questions on “Macros” along with answers, explanations and/or solutions:

1. which keyword is used to define the macros in c++?
a) macro
b) define
c) #define
d) none of the mentioned
View Answer

Answer: c
Explanation: None.

2. Which symbol is used to declare the preprocessor directives?
a) #
b) $
c) *
d) ^
View Answer

Answer: a
Explanation: None.

3. How many types of macros are there in c++?
a) 1
b) 2
c) 3
4) 4
View Answer

Answer: b
Explanation: There are two types of macros. They are object-like and function-like.

4. What is the mandatory preprosessor directive for c++?
a) #define <iostream>
b) #include <iostream>
c) #undef <iostream>
d) none of the mentioned
View Answer

Answer: b
Explanation: For a c++ program to execute, we need #include<iostream>.

5. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     #define MIN(a,b) (((a)<(b)) ? a : b)
  4.     int main ()
  5.     {
  6.         float i, j;
  7.         i = 100.1;
  8.         j = 100.01;
  9.         cout <<"The minimum is " << MIN(i, j) << endl;
  10.         return 0;
  11.     }

a) 100.01
b) 100.1
c) compile time error
d) none of the mentioned
View Answer

Answer: a
Explanation: In this program, we are getting the minimum number using conditional operator.
Output:
$ g++ mac3.cpp
$ a.out
The minimum value is 100.01

6. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         cout << "Value of __LINE__ : " << __LINE__ << endl;
  6.         cout << "Value of __FILE__ : " << __FILE__ << endl;
  7.         cout << "Value of __DATE__ : " << __DATE__ << endl;
  8.         cout << "Value of __TIME__ : " << __TIME__ << endl;
  9.         return 0;
  10.     }

a) 5
b) details about your file
c) compile time error
d) none of the mentioned
View Answer

Answer: b
Explanation: In this program, we are using the macros to print the information about the file.
Output:
$ g++ mac2.cpp
$ a.out
Value of __LINE__ : 5
Value of __FILE__ : mac1.cpp
Value of __DATE__ : Oct 10 2012
Value of __TIME__ : 22:24:37

7. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     #define SquareOf(x) x * x
  4.     int main()
  5.     {
  6.         int x;
  7.         cout << SquareOf(x + 4);
  8.         return 0;
  9.     }

a) 16
b) 64
c) compile time error
d) none of the mentioned
View Answer

Answer: d
Explanation: In this program, as we haven’t initiailzed the variable x, we will get a output of ending digit of 4.
Output:
$ g++ mac1.cpp
$ a.out
75386824

8. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     #define PR(id) cout << "The value of " #id " is "<<id
  4.     int main()
  5.     {
  6.         int i = 10;
  7.         PR(i);
  8.         return 0;
  9.     }

a) 10
b) 15
c) 20
d) none of the mentioned
View Answer

Answer: a
Explanation: In this program, we are just printing the declared values.
Output:
$ g++ mac.cpp
$ a.out
10

9. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     #define MAX 10
  4.     int main()
  5.     {
  6.         int num;
  7.         num = ++MAX;
  8.         cout << num;
  9.         return 0;
  10.     }

a) 11
b) 10
c) compile time error
d) none of the mentioned
View Answer

Answer: c
Explanation: Macro Preprocessor only replaces occurance of macro symbol with macro symbol value, So we can’t increment the value.

10. What is the other name of the macro?
a) scripted directive
b) executed directive
c) link directive
d) none of the mentioned
View Answer

Answer: a
Explanation: When the compiler encounters a previously defined macro, it will take the result from that execution itself.
Here’s the list of Best Reference Books in C++ Programming Language.

To practice all features of C++ programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on C++.

« Prev Page - C++ Programming Questions and Answers – Pointer to Function
» Next Page - C++ Programming Questions and Answers – Modularization and Interfaces
« C++ Programming Questions and Answers – Pointer to Function
C++ Programming Questions and Answers – Modularization and Interfaces »

Deep Dive @ Sanfoundry:

  1. C Questions and Answers
  2. C Programming Examples
  3. C# Programming Examples on Sorting
  4. LISP Questions and Answers
  5. C# Programming Examples
  6. Ruby Programming Questions and Answers
  7. C# Programming Examples on Functions
  8. C# Programming Examples on Delegates
  9. C Programming Examples on Stacks & Queues
  10. R Programming Questions and Answers
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and 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 & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
TOS & Privacy
Jobs
Bangalore Training
Online Training
SAN Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry