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

4/9

Page

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

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void print(int i)
{
    cout << i;
}
void print(double  f)
{
    cout << f;
}
int main(void)
{
    print(5);
    print(500.263);
    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;
#define SquareOf(x) x * x
int main()
{
    int x;
    cout << SquareOf(x + 4);
    return 0;
}

Select an option to see the answer and solution.

Pick the incorrect statement for namespaces in C++.

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;
int add (int num, ...)
{
    int sum = 0;
    va_list args;
    va_start (args,num);
    for (int i = 0; i < num; i++) 
    {
        int num = va_arg (args,int);
        sum += num;
    }
    va_end (args);
    return sum;
}
int main (void)
{
    int total = add(8, 1, 2, -1, 4, 12, -2, 9, 7);
    cout << "The result is " << total;
    return 0;
}

Select an option to see the answer and solution.

What will happen when the exception is not caught in the program?

Select an option to see the answer and solution.

What should be passed in parameters when function does not require any parameters?

Select an option to see the answer and solution.

How many types do functions fall depends on modularization?

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;
void dumplist(int, ...);
int main()
{
    dumplist(2, 4, 8);
    dumplist(3, 6, 9, 7);
    return 0;
}
void dumplist(int n, ...)
{
    va_list p;
    int i;
    va_start(p, n);
    while (n-->0) 
    {
        i = va_arg(p, int);
        cout << i;
    }
    va_end(p);
}

Select an option to see the answer and solution.

Which keyword is used to access the variable in the namespace?

Select an option to see the answer and solution.

Where can the default parameter be placed by the user?

Select an option to see the answer and solution.

What will happen while using pass by reference?

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;
namespace 
{
	int var = 10;
}
int main()
{
	cout<<var;
}

Select an option to see the answer and solution.

Which operator is used to signify the namespace?

Select an option to see the answer and solution.

which keyword is used to define the macros 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;
int operate (int a, int b)
{
    return (a * b);
}
float operate (float a, float b)
{
    return (a / b);
}
int main()
{
    int x = 5, y = 2;
    float n = 5.0, m = 2.0;
    cout << operate(x, y) <<"\t";
    cout << operate (n, m);
    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;
#define PR(id) cout << "The value of " #id " is "<<id
int main()
{
    int i = 10;
    PR(i);
    return 0;
}

Select an option to see the answer and solution.

In which of the following we cannot overload the function?

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=0, int = 0);
 
int main()
{
  cout << fun(5);
  return 0;
}
int fun(int x, int y) { return (x+y); }

Select an option to see the answer and solution.

Which keyword is used to check exception in the block of code?

Select an option to see the answer and solution.

In which of the following cases inline functions may not word?
i. If the function has static variables.
ii. If the function has global and register variables.
iii. If the function contains loops
iv. If the function is recursive

Select an option to see the answer and solution.