C++ programming functions, blocks Aptitude Questions and Answers

C++ Functions and Block based aptitude questions and answers - This section contains Aptitude Questions and Answers based on C++ functions and blocks.

List of Functions and Blocks related C++ programming Aptitude Questions and Answers

1) What will be the output of following program?
#include <iostream>
using namespace std;

void fun1(int x)
{
	cout<<x<<endl;
}

int main()
{
	//function calling
	fun1(10,20);
	return 0;
}
    
  1. Run Time Error
  2. Compile Time Error
  3. 10
  4. 10, 20

2) What will be the output of following program?
#include <iostream>
using namespace std;

int main()
{
	//function declaration
	void fun(void);
	//function calling
	fun();
	cout<<"::OK"<<endl;
	return 0;
}
//function definition
void fun(void)
{
	cout<<"Hello";
}
    
  1. Compile Time Error
  2. Run Time Error
  3. ::OK
  4. Hello::OK

3) What will be the output of following program?
#include <iostream>
using namespace std;

//declaration and definition
void print_value(int x,int y=10)
{
	cout<<"x:"<<x<<",y:"<<y<<endl;
}
int main()
{

	//function calling
	print_value(100);
	return 0;
}
    
  1. x:100,y:10
  2. x:100,y:100
  3. x:100,y:Garbage
  4. Error

4) What will be the output of following program?
#include <iostream>
using namespace std;

//declaration and definition
void fun(const int x=10)
{
	cout<<"x:"<<x<<endl;
}
int main()
{
	const int a=100;
	cout<<"call 1:";
	fun();
	cout<<"call 2:";
	fun(a);
	return 0;
}
    
  1. Call 1:x:10
    Call 2:x:100
  2. Call 1:x:10
    Call 2:x:10
  3. Call 1:x:100
    Call 2:x:100
  4. Error


5) Which is the correct form to call function fun1()?
#include <iostream>
using namespace std;

namespace myfunctions
{
	void fun1(void)
	{
		cout<<"Fun1"<<endl;
	}
}
int main()
{
	.....
	return 0;
}
    
  1. fun1();
  2. myfunctions.fun1();
  3. myfunctions::fun1();
  4. myfunctions->fun1();

6) What will be the output of following program?
#include <iostream>
using namespace std;

namespace myfunctions
{
	void fun1(void)
	{
		cout<<"Fun1"<<endl;
	}
	void fun1(int a)
	{
		cout<<a<<endl;
	}
}
int main()
{
	myfunctions::fun1(10.2f);
	return 0;
}
    
  1. Error
  2. 10
  3. 10.200000
  4. 10.2





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.