61. What will be the output of the following C++ code?
Content of header file h1.h
------------------------------------------------
h1.h
#include <iostream>
using namespace std;
namespace A{
int func(int a){
cout<<"using namespace A";
return 2*a;
}
}
------------------------------------------------
Content of header file h2.h
------------------------------------------------
h2.h
#include <iostream>
using namespace std;
namespace B{
float func(float a){
cout<<"using namespace B";
return 2*a;
}
}
------------------------------------------------
Content of program.cpp
------------------------------------------------
#include <iostream>
#include <string>
#include "h1.h"
#include "h2.h"
using namespace std;
using namespace A;
using namespace B;
int main(int argc, char const *argv[])
{
/* code */
int a = 10;
float b = 10.0;
cout<<func(a)<<endl;
cout<<func(b);
return 0;
}
-----------------------------------------------
Content of header file h1.h
------------------------------------------------
h1.h
#include <iostream>
using namespace std;
namespace A{
int func(int a){
cout<<"using namespace A";
return 2*a;
}
}
------------------------------------------------
Content of header file h2.h
------------------------------------------------
h2.h
#include <iostream>
using namespace std;
namespace B{
float func(float a){
cout<<"using namespace B";
return 2*a;
}
}
------------------------------------------------
Content of program.cpp
------------------------------------------------
#include <iostream>
#include <string>
#include "h1.h"
#include "h2.h"
using namespace std;
using namespace A;
using namespace B;
int main(int argc, char const *argv[])
{
/* code */
int a = 10;
float b = 10.0;
cout<<func(a)<<endl;
cout<<func(b);
return 0;
}
-----------------------------------------------
62. Which of the following is important in a function?
63. What will be the output of the following C++ code?
Content of header file h1.h
------------------------------------------------
h1.h
#include <iostream>
using namespace std;
namespace A{
int func(int a){
cout<<"using namespace A";
return 2*a;
}
}
------------------------------------------------
Content of header file h2.h
------------------------------------------------
h2.h
#include <iostream>
using namespace std;
namespace B{
float func(float a){
cout<<"using namespace B";
return 2*a;
}
}
------------------------------------------------
Content of program.cpp
------------------------------------------------
#include <iostream>
#include <string>
#include "h1.h"
#include "h2.h"
using namespace std;
using namespace A;
using namespace B;
int main(int argc, char const *argv[])
{
/* code */
int a = 10;
float b = 10.0;
cout<<A::func(a)<<endl;
cout<<A::func(b);
return 0;
}
------------------------------------------------
Content of header file h1.h
------------------------------------------------
h1.h
#include <iostream>
using namespace std;
namespace A{
int func(int a){
cout<<"using namespace A";
return 2*a;
}
}
------------------------------------------------
Content of header file h2.h
------------------------------------------------
h2.h
#include <iostream>
using namespace std;
namespace B{
float func(float a){
cout<<"using namespace B";
return 2*a;
}
}
------------------------------------------------
Content of program.cpp
------------------------------------------------
#include <iostream>
#include <string>
#include "h1.h"
#include "h2.h"
using namespace std;
using namespace A;
using namespace B;
int main(int argc, char const *argv[])
{
/* code */
int a = 10;
float b = 10.0;
cout<<A::func(a)<<endl;
cout<<A::func(b);
return 0;
}
------------------------------------------------
64. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
namespace first
{
int x = 5;
int y = 10;
}
namespace second
{
double x = 3.1416;
double y = 2.7183;
}
int main ()
{
using first::x;
using second::y;
bool a, b;
a = x > y;
b = first::y < second::x;
cout << a << b;
return 0;
}
#include <iostream>
using namespace std;
namespace first
{
int x = 5;
int y = 10;
}
namespace second
{
double x = 3.1416;
double y = 2.7183;
}
int main ()
{
using first::x;
using second::y;
bool a, b;
a = x > y;
b = first::y < second::x;
cout << a << b;
return 0;
}
65. Which of the header file should be added in the following C++ code to properly run the program?
#include <iostream>
using namespace std;
int print_all (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);
cout<<num<<" ";
}
va_end (args);
return sum;
}
int main (void)
{
print_all(8, 1, 2, -1, 4, 12, -2, 9, 7);
return 0;
}
#include <iostream>
using namespace std;
int print_all (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);
cout<<num<<" ";
}
va_end (args);
return sum;
}
int main (void)
{
print_all(8, 1, 2, -1, 4, 12, -2, 9, 7);
return 0;
}
66. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
namespace A{
int var = 10;
}
namespace B{
int var = 5;
}
int main()
{
int var = 20;
using namespace B;
cout<<var;
}
#include <iostream>
#include <string>
using namespace std;
namespace A{
int var = 10;
}
namespace B{
int var = 5;
}
int main()
{
int var = 20;
using namespace B;
cout<<var;
}
67. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
#define MIN(a,b) (((a)<(b)) ? a : b)
int main ()
{
float i, j;
i = 100.1;
j = 100.01;
cout <<"The minimum is " << MIN(i, j) << endl;
return 0;
}
#include <iostream>
using namespace std;
#define MIN(a,b) (((a)<(b)) ? a : b)
int main ()
{
float i, j;
i = 100.1;
j = 100.01;
cout <<"The minimum is " << MIN(i, j) << endl;
return 0;
}
68. What is the mandatory preprocessor directive for c++?
69. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void func(int x)
{
cout << x ;
}
int main()
{
void (*n)(int);
n = &func;
(*n)( 2 );
n( 2 );
return 0;
}
#include <iostream>
using namespace std;
void func(int x)
{
cout << x ;
}
int main()
{
void (*n)(int);
n = &func;
(*n)( 2 );
n( 2 );
return 0;
}
70. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void mani()
void mani()
{
cout<<"hai";
}
int main()
{
mani();
return 0;
}
#include <iostream>
using namespace std;
void mani()
void mani()
{
cout<<"hai";
}
int main()
{
mani();
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.