11. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
double & WeeklyHours()
{
double h = 46.50;
double &hours = h;
return hours;
}
int main()
{
double hours = WeeklyHours();
cout << "Weekly Hours: " << hours;
return 0;
}
#include <iostream>
using namespace std;
double & WeeklyHours()
{
double h = 46.50;
double &hours = h;
return hours;
}
int main()
{
double hours = WeeklyHours();
cout << "Weekly Hours: " << hours;
return 0;
}
12. How many minimum number of functions should be present in a C++ program for its execution?
13. What is the ability to group some lines of code that can be included?
in the program?
in the program?
14. Function overloading is also similar to which of the following?
15. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int add(int first, int second)
{
return first + second + 15;
}
int operation(int first, int second, int (*functocall)(int, int))
{
return (*functocall)(first, second);
}
int main()
{
int a;
int (*plus)(int, int) = add;
a = operation(15, 10, plus);
cout << a;
return 0;
}
#include <iostream>
using namespace std;
int add(int first, int second)
{
return first + second + 15;
}
int operation(int first, int second, int (*functocall)(int, int))
{
return (*functocall)(first, second);
}
int main()
{
int a;
int (*plus)(int, int) = add;
a = operation(15, 10, plus);
cout << a;
return 0;
}
16. What will be the output of the following C++ code?
#include <iostream>
#include <stdarg.h>
using namespace std;
void fun(std::string msg, ...);
int main()
{
fun("cPlusPlus", 1, 4, 7, 11, 0);
return 0;
}
void fun(std::string msg, ...)
{
va_list ptr;
int num;
va_start(ptr, msg);
num = va_arg(ptr, int);
num = va_arg(ptr, int);
cout << num;
}
#include <iostream>
#include <stdarg.h>
using namespace std;
void fun(std::string msg, ...);
int main()
{
fun("cPlusPlus", 1, 4, 7, 11, 0);
return 0;
}
void fun(std::string msg, ...)
{
va_list ptr;
int num;
va_start(ptr, msg);
num = va_arg(ptr, int);
num = va_arg(ptr, int);
cout << num;
}
17. What changes you can do in the header files to avoid the redefinition that compiler will give when both the header files are included in the same program keeping the declaration of both the functions same?
Content of h1.h
------------------------------------------------
h1.h
#include <iostream>
using namespace std;
int func(int a){
cout<<"Multiplied by 2";
return 2*a;
}
------------------------------------------------
Content of h2.h
------------------------------------------------
h2.h
#include <iostream>
using namespace std;
int func(int a){
cout<<"divided by 2";
return a/2;
}
------------------------------------------------
Content of h1.h
------------------------------------------------
h1.h
#include <iostream>
using namespace std;
int func(int a){
cout<<"Multiplied by 2";
return 2*a;
}
------------------------------------------------
Content of h2.h
------------------------------------------------
h2.h
#include <iostream>
using namespace std;
int func(int a){
cout<<"divided by 2";
return a/2;
}
------------------------------------------------
18. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int n(char, int);
int (*p) (char, int) = n;
int main()
{
(*p)('d', 9);
p(10, 9);
return 0;
}
int n(char c, int i)
{
cout << c << i;
return 0;
}
#include <iostream>
using namespace std;
int n(char, int);
int (*p) (char, int) = n;
int main()
{
(*p)('d', 9);
p(10, 9);
return 0;
}
int n(char c, int i)
{
cout << c << i;
return 0;
}
19. Where does the execution of the program starts?
20. When we define the default values for a function?
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.