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 – Unspecified Number of Arguments

Posted on November 13, 2012 by Manish
This section on C++ Programming quiz focuses on “Unspecified Number of Arguments”. 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++ Programming quiz on “Unspecified Number of Arguments” along with answers, explanations and/or solutions:

1. Which header file is used to pass unknown number of arguments to function?
a) stdlib.h
b) string.h
c) stdarg.h
d) none of the mentioned
View Answer

Answer: c
Explanation: Because the cstdarg defines this header file to process the unknown number of arguments.
advertisement

2. How can you access the arguments that are manipulated in the function?
a) va_list
b) arg_list
c) both va_list & arg_list
d) none of the mentioned
View Answer

Answer: a
Explanation: va_list is provided by C++ to access manipulated arguments in function.

3. What is the output of this program?

  1.     #include <iostream>
  2.     #include <stdarg.h>
  3.     using namespace std;
  4.     float avg( int Count, ... )
  5.     {
  6.         va_list Numbers;
  7.         va_start(Numbers, Count);
  8.         int Sum = 0;
  9.         for (int i = 0; i < Count; ++i )
  10.             Sum += va_arg(Numbers, int);
  11.         va_end(Numbers);
  12.         return (Sum/Count);
  13.     }
  14.     int main()
  15.     {
  16.         float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
  17.         cout << "Average of first 10 whole numbers : " << Average;
  18.         return 0;
  19.     }

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

Answer: a
Explanation: We are just calculating the average of these numbers using cstdarg.
Output:

$ g++ uka.cpp
$ a.out
Average of first 10 whole numbers 4

4. What is the maximum number of arguments or parameters that can be
present in one function call?
a) 64
b) 256
c) 255
d) 16
View Answer

Answer: b
Explanation: C++ allows maximum number of 256 arguments in a function call.

5. What is the output of this program?

advertisement
  1.     #include <iostream>
  2.     #include <stdarg.h>
  3.     using namespace std;
  4.     int add (int num, ...)
  5.     {
  6.         int sum = 0;
  7.         va_list args;
  8.         va_start (args,num);
  9.         for (int i = 0; i < num; i++) 
  10.         {
  11.             int num = va_arg (args,int);
  12.             sum += num;
  13.         }
  14.         va_end (args);
  15.         return sum;
  16.     }
  17.     int main (void)
  18.     {
  19.         int total = add(8, 1, 2, -1, 4, 12, -2, 9, 7);
  20.         cout << "The result is " << total;
  21.         return 0;
  22.     }

a) 32
b) 23
c) 48
d) compile time error
View Answer

Answer: a
Explanation: We are adding these numbers by using for statement and stdarg.
Output:

$ g++ uka.cpp
$ a.out
The result is 32

6. What is the output of this program?

  1.     #include <iostream>
  2.     #include <stdarg.h>
  3.     using namespace std;
  4.     void dumplist(int, ...);
  5.     int main()
  6.     {
  7.         dumplist(2, 4, 8);
  8.         dumplist(3, 6, 9, 7);
  9.         return 0;
  10.     }
  11.     void dumplist(int n, ...)
  12.     {
  13.         va_list p;
  14.         int i;
  15.         va_start(p, n);
  16.         while (n-->0) 
  17.         {
  18.             i = va_arg(p, int);
  19.             cout << i;
  20.         }
  21.         va_end(p);
  22.     }

a) 2436
b) 48697
c) 1111111
d) compile time error
View Answer

Answer: b
Explanation: In this program, we are eradicating the first value
by comparing using while operator.
Output:

$ g++ rka3.cpp
$ a.out
48697

advertisement

7. What is the output of this program?

  1.     #include <iostream>
  2.     #include <stdarg.h>
  3.     using namespace std;
  4.     int flue(char c,...);
  5.     int main()
  6.     {
  7.         int x, y;
  8.         x = flue('A', 1, 2, 3);
  9.         y = flue('1', 1.0,1, '1', 1.0f, 1l);
  10.         cout << x << y;
  11.         return 0;
  12.     }
  13.     int flue(char c,...)
  14.     {
  15.         return c;
  16.     }

a) 6549
b) 4965
c) 6646
d) compile time error
View Answer

Answer: a
Explanation: In this program, we are returning the ascii value of the character and printing it.
Output:

$ g++ rka4.cpp
$ a.out
6549

8. Which of the header file should be added in the below code to properly run the program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int print_all (int num, ...)
  4.     {
  5.         int sum = 0;
  6.         va_list args;
  7.         va_start (args,num);
  8.         for (int i = 0; i < num; i++) 
  9.         {
  10.             int num = va_arg (args,int);
  11.             cout<<num<<" ";
  12.         }
  13.         va_end (args);
  14.         return sum;
  15.     }
  16.     int main (void)
  17.     {
  18.         print_all(8, 1, 2, -1, 4, 12, -2, 9, 7);
  19.         return 0;
  20.     }

a) stdlib.h
b) stdarg.h
c) string.h
d) stdpar.h
View Answer

Answer: b
Explanation: <stdarg.h> header provided to perform variable number of argument passing.

9. What is the output of this program?

  1.     #include <iostream>
  2.     #include <stdarg.h>
  3.     using namespace std;
  4.     void fun(std::string msg, ...);
  5.     int main()
  6.     {
  7.         fun("IndiaBIX", 1, 4, 7, 11, 0);
  8.         return 0;
  9.     }
  10.     void fun(std::string msg, ...)
  11.     {
  12.         va_list ptr;
  13.         int num;
  14.         va_start(ptr, msg);
  15.         num = va_arg(ptr, int);
  16.         num = va_arg(ptr, int);
  17.         cout << num;
  18.     }

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

Answer: d
Explanation: In this program, we are moving the pointer to the second value and printing it.
Output:

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

10. What will initialize the list of arguments in stdarg.h header file?
a) va_list
b) va_start
c) va_arg
d) none of the mentioned
View Answer

Answer: b
Explanation: va_start initialises the the list of arguments in <stdarg.h> header file.

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 – Default Arguments
» Next Page - C++ Programming Questions and Answers – Pointer to Function

« C++ Programming Questions and Answers – Default Arguments
C++ Programming Questions and Answers – Pointer to Function »
advertisement

Deep Dive @ Sanfoundry:

  1. C Programming Examples on Bitwise Operations
  2. Python Programming Examples
  3. Ruby Programming Questions and Answers
  4. C++ Questions and Answers
  5. Java Programming Examples
  6. Java Programming Examples on File Handling
  7. C Programming Examples
  8. C Programming Examples on File Handling
  9. Object Oriented Programming Questions and Answers
  10. C# Programming Examples on LINQ
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.