1. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void Values(int n1, int n2 = 10)
{
using namespace std;
cout << "1st value: " << n1;
cout << "2nd value: " << n2;
}
int main()
{
Values(1);
Values(3, 4);
return 0;
}
#include <iostream>
using namespace std;
void Values(int n1, int n2 = 10)
{
using namespace std;
cout << "1st value: " << n1;
cout << "2nd value: " << n2;
}
int main()
{
Values(1);
Values(3, 4);
return 0;
}
2. What is the maximum number of arguments or parameters that can be present in one function call?
3. How to print the value of the i variable inside namespace B?
namespace A{
int var = 10;
namespace B{
int i = 15;
}
}
namespace A{
int var = 10;
namespace B{
int i = 15;
}
}
4. What is the use of Namespace?
5. How can you access the arguments that are manipulated in the function?
6. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
namespace first
{
int var = 5;
}
namespace second
{
double var = 3.1416;
}
int main ()
{
int a;
a = first::var + second::var;
cout << a;
return 0;
}
#include <iostream>
using namespace std;
namespace first
{
int var = 5;
}
namespace second
{
double var = 3.1416;
}
int main ()
{
int a;
a = first::var + second::var;
cout << a;
return 0;
}
7. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int age = 0;
try
{
if (age < 0)
{
throw "Positive Number Required";
}
cout << age;
}
catch(const char *Message)
{
cout << "Error: " << Message;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int age = 0;
try
{
if (age < 0)
{
throw "Positive Number Required";
}
cout << age;
}
catch(const char *Message)
{
cout << "Error: " << Message;
}
return 0;
}
8. What is the correct syntax of defining a namespace?
9. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
char* buff;
try
{
buff = new char[1024];
if (buff == 0)
throw "Memory allocation failure!";
else
cout << sizeof(buff) << "Byte successfully allocated!"<<endl;
}
catch(char *strg)
{
cout<<"Exception raised: "<<strg<<endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
char* buff;
try
{
buff = new char[1024];
if (buff == 0)
throw "Memory allocation failure!";
else
cout << sizeof(buff) << "Byte successfully allocated!"<<endl;
}
catch(char *strg)
{
cout<<"Exception raised: "<<strg<<endl;
}
return 0;
}
10. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int gcd (int a, int b)
{
int temp;
while (b != 0)
{
temp = a % b;
a = b;
b = temp;
}
return(a);
}
int main ()
{
int x = 15, y = 25;
cout << gcd(x, y);
return(0);
}
#include <iostream>
using namespace std;
int gcd (int a, int b)
{
int temp;
while (b != 0)
{
temp = a % b;
a = b;
b = temp;
}
return(a);
}
int main ()
{
int x = 15, y = 25;
cout << gcd(x, y);
return(0);
}
Read More Section(Functions and Procedures in C plus plus)
Each Section contains maximum 100 MCQs question on Functions and Procedures in C plus plus. To get more questions visit other sections.