Vidyalelo
C++ Programming · all questions

Functions and Procedures in C++
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

176

Questions

7/9

Page

Pick an option on a question to see the right answer and solution.

How many types of returning values are present in c++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include<iostream>
using namespace std;
 
class Test
{
  protected:
    int x;
  public:
    Test (int i):x(i) { }
    void fun() const  { cout << "fun() const " << endl; }
    void fun()        {  cout << "fun() " << endl;     }
};
 
int main()
{
    Test t1 (10);
    const Test t2 (20);
    t1.fun();
    t2.fun();
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <stdarg.h>
using namespace std;
float avg( int Count, ... )
{
    va_list Numbers;
    va_start(Numbers, Count);
    int Sum = 0;
    for (int i = 0; i < Count; ++i )
        Sum += va_arg(Numbers, int);
    va_end(Numbers);
    return (Sum/Count);
}
int main()
{
    float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    cout << "Average of first 10 whole numbers : " << Average;
    return 0;
}

Select an option to see the answer and solution.

Which of the following implements the module in the program?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include<iostream>
using namespace std;
 
int fun(int x = 0, int y = 0, int z)
{  return (x + y + z); }
 
int main()
{
   cout << fun(10);
   return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
    cout << "Value of __LINE__ : " << __LINE__ << endl;
    cout << "Value of __FILE__ : " << __FILE__ << endl;
    cout << "Value of __DATE__ : " << __DATE__ << endl;
    cout << "Value of __TIME__ : " << __TIME__ << endl;
    return 0;
}

Select an option to see the answer and solution.

When will we use the function overloading?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void copy (int& a, int& b, int& c)
{
    a *= 2;
    b *= 2;
    c *= 2;
}
int main ()
{
    int x = 1, y = 3, z = 7;
    copy (x, y, z);
    cout << "x =" << x << ", y =" << y << ", z =" << z;
    return 0;
}

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void square (int *x, int *y)
{
	*x = (*x) * --(*y);
}
int main ( )
{
	int number = 30;
	square(&number, &number);
	cout << number;
	return 0;
}

Select an option to see the answer and solution.

What is the default return type of a function?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
string askNumber(string prompt = "Please enter a number: ");
int main()
{
    string number = askNumber();
    cout << "Here is your number: " << number;
    return 0;
}
string askNumber(string prompt)
{
    string number;
    cout << prompt;
    cin << number;
    return number;
}

Select an option to see the answer and solution.

What are mandatory parts in the function declaration?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int add(int a, int b);
int main()
{
    int i = 5, j = 6;
    cout << add(i, j) << endl;
    return 0;
}
int add(int a, int b )
    {
        int sum = a + b;
        a = 7;
        return a + b;
    }

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int max(int a, int b )
{
    return ( a > b ? a : b );
}
int main()
{
    int i = 5;
    int j = 7;
    cout << max(i, j );
    return 0;
}

Select an option to see the answer and solution.

How many types of modularization are there in c++?

Select an option to see the answer and solution.

By default how the value are passed in c++?

Select an option to see the answer and solution.

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void PrintSequence(int StopNum)
{
    int Num;
    Num = 1;
    while (true) 
    {
        if (Num >= StopNum)
            throw Num;
        cout << Num;
        Num++;
    }
}
int main(void)
{
    try 
    {
        PrintSequence(20);
    }
    catch(int ExNum)
    {
        cout << "Caught an exception with value: " << ExNum;
    }
    return 0;
}

Select an option to see the answer and solution.

What will we not do with function pointers?

Select an option to see the answer and solution.

Which header file is used to pass unknown number of arguments to function?

Select an option to see the answer and solution.

What will be the new value of x in the following C++ code?
#include <iostream>
using namespace std;
void fun(int &x)
{
    x = 20;
}
int main()
{
     int x = 10;
     fun(x);
     cout << "New value of x is " << x;
     return 0;
}

Select an option to see the answer and solution.