Home / Programming Questions / C++ MCQs / Page 1

C++ MCQs with answers Page - 1

Dear candidates you will find MCQ questions of C++ here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question

U

Uday Singh • 7K Points
Tutor III

Q. What will initialize the list of arguments in stdarg.h header file?

(A) va_start
(B) va_arg
(C) va_list
(D) All of above

U

Uday Singh • 7K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    #include 
    using namespace std;
    void function(std::string message, ...);
    int main()
    {
        function("UdayMCQBuddy", 5, 7, 10, 8, 9);
        return 0;
    }
    void function(std::string message, ...)
    {
        va_list ptr;
        int number;
        va_start(ptr, message);
        number = va_arg(ptr, int);
        number = va_arg(ptr, int);
        cout << number;
    }
(A) UdayMCQBuddy
(B) 5
(C) 7
(D) 8

U

Uday Singh • 7K Points
Tutor III

Q. Which header file should you include if you are to develop a function that can accept variable number of arguments?

(A) stdio.h
(B) varag.h
(C) stdarg.h
(D) stdlib.h

U

Uday Singh • 7K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    #include 
    using namespace std;
    int funcion(char ch,...);
    int main()
    {
        int p, q;
        p = funcion('B', 2, 3, 4);
        q = funcion('3', 2.0, 2, '3', 2.0f, 10);
        cout << p<<" " << q;
        return 0;
    }
    int funcion(char ch,...)
    {
        return ch;
    }
(A) 51 66
(B) 66 51
(C) Compilation Error
(D) Runtime Error

U

Uday Singh • 7K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    #include 
    using namespace std;
    void List(int, ...);
    int main()
    {
        List(2, 5, 10);
        List(3, 6, 9, 7);
        return 0;
    }
    void List(int num, ...)
    {
        va_list a;
        int k;
        va_start(a, num);
        while (num-->0) 
        {
            k = va_arg(a, int);
            cout << k;
        }
        va_end(a);
    }
(A) 2 5 10 3 6 9 7
(B) 2 3 5 6 7 9 10
(C) 10 9 7 6 5 3 2
(D) 5 10 6 9 7

U

Uday Singh • 7K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    #include 
    using namespace std;
    int Addition(int number, ...)
    {
        int sum = 0;
        va_list args;
        va_start (args,number);
        for (int i = 0; i < number; i++) 
        {
            int number = va_arg (args,int);
            sum += number;
        }
        va_end (args);
        return sum;
    }
    int main (void)
    {
        int Result = Addition(1, 10, 9, -1, 13, 23, -2, 9, 17);
        cout << "The result is " << Result;
        return 0;
    }
(A) 1
(B) 5
(C) 10
(D) 20

U

Uday Singh • 7K Points
Tutor III

Q. What is the maximum number of arguments or parameters that can be present in one function call?

(A) 16
(B) 256
(C) 255
(D) 64

U

Uday Singh • 7K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    #include 
    using namespace std;
    float avg( int Count, ... )
    {
        va_list num;
        va_start(num, Count);
        int Sum = 0;
        for (int i = 0; i < Count; ++i )
            Sum += va_arg(num, int);
        va_end(num);
        return (Sum/Count);
    }
    int main()
    {
        float AVG = avg(5, 0, 1, 2, 3, 4);
        cout << "Average of first 5 whole numbers : " << AVG;
        return 0;
    }
(A) 2
(B) 3
(C) 4
(D) 5

Login

Forgot username? click here

Forgot password? Click here

Don't have account? Register here.