logo
  • Home
  • Rank
  • Tests
  • 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
Practice 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

C++ Tests

C++ Tests

Best Reference Books

C++ Books
« Prev Page
Next Page »

C++ Programming Questions and Answers – Sizes

Posted on November 13, 2012 by Manish
This section on C++ interview questions and answers focuses on “Sizes”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in 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 the detailed explanation of the answers which helps in better understanding of C++ concepts.

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

1. The size of an object or a type can be determined using which operator?
a) malloc
b) sizeof
c) malloc
d) calloc
View Answer

Answer: b
Explanation: The sizeof operator gives the size of the object or type.
advertisement

2. It is guaranteed that a ____ has at least 8 bits and a ____ has at least 16 bits.
a) int, float
b) char, int
c) bool, char
d) char, short
View Answer

Answer: d
Explanation: char types in C++ require atleast 8 bits and short requires atleast 16 bits, whereas for bool only 1 bit suffices and both int and float requires atleast 32 bits.

3. Implementation dependent aspects about an implementation can be found in ____
a) <implementation>
b) <limits>
c) <limit>
d) <numeric>
View Answer

Answer: b
Explanation: The limit header holds the details of the machine dependent details.

4. Size of C++ objects are expressed in terms of multiples of the size of a ____ and the size of a char is _______
a) char, 1
b) int, 1
c) float, 8
d) char, 4
View Answer

Answer: a
Explanation: Each object in C++ is expressed in terms of char type and size of char type is one byte.

5. Identify the incorrect option.
a) 1 <= sizeof(bool) <= sizeof(long)
b) sizeof(float) <= sizeof(double) <= sizeof(long double)
c) sizeof(char) <= sizeof(long) <=sizeof(wchar_t)
d) sizeof(N) = sizeof(signed N) = sizeof(unsigned N)
View Answer

Answer: c
Explanation: sizeof(char) <= sizeof(wchar_t) <= sizeof(long).

6. What is the output of the following program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int num = 0x20 + 020 + 20;
  6.         cout << sizeof(num)<<'\n';
  7.         return 0;
  8.     }

a) 2
b) 4
c) Depends on compiler
d) Garbage
View Answer

Answer: c
Explanation: The sum of three numbers are belongs to different number systems, so the result is type casted into integer.
Output:

$ g++ size.cpp
$ a.out
4

7. What is the output of the following program?

advertisement
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main ( )
  4.     {
  5.         static double i;
  6.         i = 20;
  7.         cout << sizeof(i);
  8.         return 0;
  9.     }

a) 4
b) 2
c) 8
d) garbage
View Answer

Answer: c
Explanation: The size of the double data type is 8.

$ g++ size1.cpp
$ a.out
8

8. What is the output of the following program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int num1 = 10;
  6.         float num2 = 20;
  7.         cout << sizeof(num1 + num2);
  8.         return 0;
  9.     }

a) 2
b) 4
c) 8
d) garbage
View Answer

Answer: b
Explanation: In this program, integer is converted into float. Therefore the result of num1 and num2 is float. And it is returning the size of the float.
Output:

$ g++ size2.cpp
$ a.out
4

9. What is the output of the following program?

advertisement
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int a = 5;
  6.         float b;
  7.         cout << sizeof(++a + b);
  8.         cout << a;
  9.         return 0;
  10.     }

a) 2 6
b) 4 6
c) 2 5
d) 4 5
View Answer

Answer: d
Explanation: The a as a integer will be converted to float while calculating the size. The value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5.
Output:

$ g++ size3.cpp
$ a.out
4 5

10. What would be the output of the following program (in 32-bit systems)?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         cout << sizeof(char);
  6.         cout << sizeof(int);
  7.         cout << sizeof(float);
  8.         return 0;
  9.     }

a) 1 4 4
b) 1 4 8
c) 1 8 8
d) none of the mentioned
View Answer

Answer: a
Explanation: Character is 1 byte, integer 4 bytes and float 4 bytes.

Sanfoundry Global Education & Learning Series – C++ Programming Language.

C++ Practice Resources
C++ Mock Tests & Certification Test | 1000 C++ MCQs | 1000 C++ Algorithms | Best C++ Books
« Prev Page - C++ Programming Questions and Answers – Floating Point Types
» Next Page - C++ Programming Questions and Answers – Void

« C++ Programming Questions and Answers – Floating Point Types
C++ Programming Questions and Answers – Void »
advertisement

Deep Dive @ Sanfoundry:

  1. C Programming Examples
  2. Java Programming Examples on File Handling
  3. R Programming Questions and Answers
  4. Ruby Programming Questions and Answers
  5. C Questions and Answers
  6. C Programming Examples on Bitwise Operations
  7. Java Programming Examples on Inheritance
  8. C# Programming Examples on LINQ
  9. Object Oriented Programming Questions and Answers
  10. 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
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.