logo
  • Home
  • Test & Rank
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Mining
  • Marine
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Jobs
  • 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

•   C++ Basics
•   OOPs Concept - 1
•   OOPs Concept - 2
•   OOPs Concept - 3
•   OOPs Concept - 4
•   C++ vs C
•   C++ Concepts - 1
•   C++ Concepts - 2
•   C++ Concepts - 3
•   Static Constant Keyword
•   Types
•   Booleans
•   Character Types
•   Integer Types
•   Floating Point Types
•   Sizes
•   Void
•   Enumerations
•   Declaration
•   Pointers
•   Arrays
•   Pointers into Arrays
•   Constants
•   References - 1
•   References - 2
•   References - 3
•   Pointer to Void
•   Structures
•   Character Classification
•   Operators
•   Statements
•   Comments & Indentation
•   Function Declarations
•   Functions
•   Argument Passing
•   Value Return
•   Overloaded Function
•   Default Arguments
•   Unspecified Arguments
•   Pointer to Function
•   Macros
•   Modularization
•   Namespaces - 1
•   Namespaces - 2
•   Exceptions
•   Linkage
•   Header Files Usage
•   Classes - 1
•   Classes - 2
•   User Defined Types
•   Objects
•   Operator Functions
•   Operator Overloading - 1
•   Operator Overloading - 2
•   Complex Number Type
•   Conversion Operators
•   Friends
•   Friend Function
•   Large Objects
•   Essential Operators
•   Subscripting
•   Function Call
•   Dereferencing
•   Increment & Decrement
•   String Class
•   String - 1
•   String - 2
•   Constructor & Destructor-1
•   Constructor & Destructor-2
•   Constructor & Destructor-3
•   Derived Classes
•   Abstract Classes - 1
•   Abstract Classes - 2
•   Class Hierarchies
•   Abstract Classes
•   Simple String Template
•   Function Templates - 1
•   Function Templates - 2
•   Class Templates
•   Policy Usage Template
•   Specialization
•   Derivation & Templates
•   Standard Template Library
•   Templates
•   Error Handling
•   Exceptions Grouping
•   Catching Exceptions
•   Resource Management
•   Exceptions Not Errors
•   Exception Specifications
•   Uncaught Exceptions
•   Exceptions & Efficiency
•   Exception Handling - 1
•   Exception Handling - 2
•   Exception Handling - 3
•   Error Handling Alternatives
•   Standard Exceptions
•   Class Hierarchies
•   Multiple Inheritance
•   Inheritance - 1
•   Inheritance - 2
•   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
•   seq_con Array Class - 1
•   seq_con Array Class - 2
•   seq_con Vector Class - 1
•   seq_con Vector Class - 2
•   seq_con List
•   STL - Pair
•   STL Container Any - 1
•   STL Container Any - 2
•   STL - Heap
•   vtable & vptr
•   Generators
•   Array Type Manipulation
•   Tuples - 1
•   Tuples - 2
•   Complex Library - 1
•   Complex Library - 2
•   Valarray
•   Bitset - 1
•   Bitset - 2
•   Bitset - 3
•   Class Relationships
•   More Containers
•   Library Algorithms
•   Sequences / Containers
•   Function Objects
•   Nonmodifying Algorithms
•   Modifying Algorithms
•   Stored Sequences
•   Heaps
•   Min & Max
•   Permutations
•   C Style Algorithms
•   Iterators & Sequences
•   Checked Iterators
•   Allocators
•   Iterators
•   STL Algorithms
•   Functors
•   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
•   File Handling
•   Lambda Expressions
•   Command Line Arguments

Best Reference Books

C++ Books

C++ Programming Tests

Certification Test
Internship Test
Job Test
All Tests
Top Rankers
Practice Test 1
Practice Test 2
Practice Test 3
Practice Test 4
Practice Test 5
Practice Test 6
Practice Test 7
Practice Test 8
Practice Test 9
Practice Test 10
Mock Test 1
Mock Test 2
Mock Test 3
Mock Test 4
Mock Test 5
Mock Test 6
Mock Test 7
Mock Test 8
Mock Test 9
Mock Test 10
« Prev Page
Next Page »

C++ Programming Questions and Answers – Function Call

Posted on November 13, 2012 by Manish
This section on C++ quiz focuses on “Function Call”. One shall practice these quizzes 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++ quiz comes with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ quiz on “Function Call” along with answers, explanations and/or solutions:

1. What is the use of function call operator?
a) overloading the methods
b) overloading the objects
c) overloading the parameters
d) overloading the string
View Answer

Answer: b
Explanation: Overloading the objects is the use of function call operator.
advertisement

2. Pick out the correct statement.
a) virtual functions does not give the ability to write a templated function
b) virtual functions does not give the ability to rewrite a templated function
c) virtual functions does give the ability to write a templated function
d) virtual functions does not give the ability to rewrite a simple function
View Answer

Answer: a
Explanation: Virtual functions does not give the ability to write a templated function.

3. What will happen when the function call operator is overloaded?
a) It will not modify the functions
b) It will modify the functions
c) It will modify the object
d) It will modify the operator to be interpreted
View Answer

Answer: d
Explanation: It will modifies how the operator is to be interpreted when applied to objects of a given type.

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

  1.     #include <iostream>
  2.     using namespace std;
  3.     class Distance
  4.     {
  5.         private:
  6.         int feet;
  7.         int inches;
  8.         public:
  9.         Distance()
  10.         {
  11.             feet = 0;
  12.             inches = 0;
  13.         }
  14.         Distance(int f, int i) 
  15.         {
  16.             feet = f;
  17.             inches = i;
  18.         }
  19.         Distance operator()(int a, int b, int c)
  20.         {
  21.             Distance D;
  22.             D.feet = a + c + 10;
  23.             D.inches = b + c + 100 ;
  24.             return D;
  25.         }
  26.         void displayDistance()
  27.         {
  28.             cout  << feet <<  inches << endl;
  29.         }
  30.     };
  31.     int main()
  32.     {
  33.         Distance D1(11, 10), D2;
  34.         cout << "First Distance : ";
  35.         D1.displayDistance();
  36.         D2 = D1(10, 10, 10);
  37.         cout << "Second Distance :";
  38.         D2.displayDistance();
  39.         return 0;
  40.     }

a)

   First Distance : 1110
   Second Distance :30120

b)

   First Distance : 110
   Second Distance :3020

c)

   First Distance : 1115
   Second Distance :30125

d) pre> First Distance : 100
Second Distance :30120
View Answer

Answer: a
Explanation: We are calculating the foot and inches by using the function call operator.
Output:

advertisement
$ g++ call.cpp
$ a.out
First Distance : 1110
Second Distance :30120
 
 

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

  1.     #include <iostream>
  2.     using namespace std;
  3.     void duplicate (int& a, int& b, int& c)
  4.     {
  5.         a *= 2;
  6.         b *= 2;
  7.         c *= 2;
  8.     }
  9.     int main ()
  10.     {
  11.         int x = 1, y = 3, z = 7;
  12.         duplicate (x, y, z);
  13.         cout << x << y << z;
  14.         return 0;
  15.     }

a) 1468
b) 2812
c) 2614
d) 2713
View Answer

Answer: c
Explanation: We are passing the values by reference and modified the data on the function block.
Output:

$ g++ call1.cpp
$ a.out
2614

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

  1.     #include <iostream>
  2.     using namespace std;
  3.     class three_d 
  4.     {
  5.         int x, y, z;
  6.         public:
  7.         three_d() { x = y = z = 0; }
  8.         three_d(int i, int j, int k) { x = i; y = j; z = k; }
  9.         three_d operator()(three_d obj);
  10.         three_d operator()(int a, int b, int c);
  11.         friend ostream &operator<<(ostream &strm, three_d op);
  12.     };
  13.     three_d three_d::operator()(three_d obj)
  14.     {
  15.         three_d temp;
  16.         temp.x = (x + obj.x) / 2;
  17.         temp.y = (y + obj.y) / 2;
  18.         temp.z = (z + obj.z) / 2;
  19.         return temp;
  20.     }
  21.     three_d three_d::operator()(int a, int b, int c)
  22.     {
  23.         three_d temp;
  24.         temp.x = x + a;
  25.         temp.y = y + b;
  26.         temp.z = z + c;
  27.         return temp;
  28.     }
  29.         ostream &operator<<(ostream &strm, three_d op) {
  30.         strm << op.x << ", " << op.y << ", " << op.z << endl;
  31.         return strm;
  32.     }
  33.     int main()
  34.     {
  35.         three_d objA(1, 2, 3), objB(10, 10, 10), objC;
  36.         objC = objA(objB(100, 200, 300));
  37.         cout << objC;
  38.         return 0;
  39.     }

a) 55, 106, 156
b) 55, 106
c) 55, 106, 159
d) 55, 106, 158
View Answer

Answer: a
Explanation: In this program, We are using the function call operator to calculate the value of objc.
Output:

advertisement
$ g++ call2.cpp
$ a.out
55, 106, 156

7. What will be the output of the following C++ code?

  1.     #include <iostream>
  2.     using namespace std;
  3.     class Complex
  4.     {
  5.         private:
  6.         float real;
  7.         float imag;
  8.         public:
  9.         Complex():real(0), imag(0){}
  10.         Complex operator ()(float re, float im)
  11.         {
  12.             real += re;
  13.             imag += im;
  14.             return *this;
  15.         }
  16.         Complex operator() (float re)
  17.         {
  18.             real += re;
  19.             return *this;
  20.         }
  21.         void display()
  22.         {
  23.             cout << "(" << real << "," << imag << ")" << endl;
  24.         }
  25.     };
  26.     int main()
  27.     {
  28.         Complex c1, c2;
  29.         c2 = c1(3.2, 5.3);
  30.         c1(6.5, 2.7);
  31.         c2(1.9);
  32.         cout << "c2=";c1.display();
  33.         cout << "c2=";c2.display();
  34.         return 0;
  35.     }

a)

   c2=(9.7,8)
   c2=(5.1,5.3)

b)

   c2=(9,8)
   c2=(5,5)

c)

   c2=(4.7,8)
   c2=(2.1,5.3)

d)

   c2=(5.7,8)
   c2=(5.1,5.6)
View Answer
Answer: a
Explanation: In this program, We are returning the real and imaginary part of the complex number by using function call operator.
Output:

$ g++ call3.cpp
$ a.out
c2=(9.7,8)
c2=(5.1,5.3)
 
 

8. In which form does the function call operator can be overloaded?
a) static member function
b) non-static member function
c) dynamis_cast
d) static_cast
View Answer

Answer: b
Explanation: In non-static member function, the function call operator can be overloaded.

9. What will be the output of the following C++ code?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int operate (int a, int b)
  4.     {
  5.         return (a * b);
  6.     }
  7.     float operate (float a, float b)
  8.     {
  9.         return (a / b);
  10.     }
  11.     int main ()
  12.     {
  13.         int x = 5, y = 2;
  14.         float n = 5.0, m = 2.0;
  15.         cout << operate (x, y);
  16.         cout << operate (n, m);
  17.         return 0;
  18.     }

a) 119
b) 102.5
c) 123.4
d) 128.4
View Answer

Answer: b
Explanation: In this program, We are overloading the function and getting the output as 10 and 2.5 by division and multiplication.
Output:

$ g++ call3.cpp
$ a.out
102.5

10. What is the use of functor?
a) It makes the object “callable” like a function
b) It makes the class “callable” like a function
c) It makes the attribute “callable” like a function
d) It makes the argument “callable” like a function
View Answer

Answer: a
Explanation: functor makes the object “callable” like a function.

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 – Subscripting
» Next Page - C++ Programming Questions and Answers – Dereferencing

« C++ Programming Questions and Answers – Subscripting
C++ Programming Questions and Answers – Dereferencing »
advertisement

Deep Dive @ Sanfoundry:

  1. Python Programming Examples
  2. C Programming Examples
  3. Java Programming Examples on Mathematical Functions
  4. R Programming Questions and Answers
  5. C++ Questions and Answers
  6. C# Programming Examples on Functions
  7. Python Questions and Answers
  8. Ruby Programming Questions and Answers
  9. C# Programming Examples on Delegates
  10. Object Oriented Programming Questions and Answers
Manish Bhojasia
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 | Facebook | Twitter

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.