c语言编程1+2+3_C ++编程功能,阻止能力倾向问题和解答

c语言编程1+2+3

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

基于C ++函数和块的能力倾向问题和答案 -本节包含基于C ++函数和块的能力倾向问题和答案。

与C ++编程相关的功能和块列表适度性问答 (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

Answer
Correct Answer - 2

Compile Time Error
Since function declaration has only one integer argument while we are passing to arguments, hence program will through compiler error.

1)以下程序的输出是什么?
  1. 运行时错误

  2. 编译时错误

  3. 10

  4. 10、20

回答
正确答案-2

编译时错误
由于函数声明在传递给参数时只有一个整数参数,因此程序将通过编译器错误。

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

Answer
Correct Answer - 4

Hello::OK
We can declare any function within the main().

2)以下程序的输出是什么?
  1. 编译时错误

  2. 运行时错误

  3. ::好

  4. 您好:好的

回答
正确答案-4

您好:好的
我们可以在main()中声明任何函数。

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

Answer
Correct Answer - 1

x:100,y:10
In the function declaration, argument y is a default parameter and while calling we are not passing second parameter hence 10 will be the value of second parameter y.

3)以下程序的输出是什么?
  1. x:100,y:10

  2. x:100,y:100

  3. x:100,y:垃圾

  4. 错误

回答
正确答案-1

x:100,y:10
在函数声明中,参数y是默认参数,在调用时我们没有传递第二个参数,因此10将是第二个参数y的值。

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

Answer
Correct Answer - 1

Call 1:x:10
Call 2:x:100

In the first calling there is no parameter, hence default value 10 will be printed and in the second calling 100 is passing as a parameter so 100 will be printed after second calling.

4)以下程序的输出是什么?
  1. 通话1:x:10
    通话2:x:100

  2. 通话1:x:10
    通话2:x:10

  3. 通话1:x:100
    通话2:x:100

  4. 错误

回答
正确答案-1

通话1:x:10
通话2:x:100
在第一个调用中没有参数,因此将打印默认值10,在第二个调用中传递100作为参数,因此将在第二个调用后打印100。

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();

Answer
Correct Answer - 3

myfunctions::fun1();
fun1() is declared and define within the namespace and we can access a function of a namespace using Scope Resolution Operator (::).

5)调用函数 fun1()的正确形式是什么?
  1. fun1();

  2. myfunctions.fun1();

  3. myfunctions :: fun1();

  4. myfunctions-> fun1();

回答
正确答案-3

myfunctions :: fun1();
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

Answer
Correct Answer - 2

10
In the namespace there are two functions with same name (it is called function overloading), we are calling fun1 with value 10.2f and this value will convert into integer (implicit conversion) hence second fun1 will be called.

6)以下程序的输出是什么?
  1. 错误

  2. 10

  3. 10.200000

  4. 10.2

回答
正确答案-2

10
在命名空间中,有两个具有相同名称的函数(称为函数重载),我们正在调用fun1,其值为10.2f,该值将转换为整数(隐式转换),因此将调用第二个fun1。

翻译自: https://www.includehelp.com/cpp-programming/functions-blocks-aptitude-questions-answers.aspx

c语言编程1+2+3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、打开vc++6。具体操作是:鼠标依次单击电脑屏幕左下角开始、Microsoft Visual Studio 6.0、 MicrosoftVisualC++6.0(小麻花图标) 二、新建MFC工程。具体操作是:鼠标依次单击“文件”、“新建”、“MFC AppWizard[exe]” 然后在右侧上部“C位置”上部的空白处填写工程的名字可以用“201909011351”命名意思是2019年09月01日13时51分。以时间命名 然后单击“右下角确定”、出现对话框选择“D基本对话”单击“完成”再单击“确定”。至此MFC空工程就建立好了。 三、添加3个输入框。具体操作是:用鼠标拖动3个“Edit Box”“abl”图标,到程序主界面。再拖一个按钮“Button”到程序主界面。 提示:如果主程序界面找不到了怎么办?点击“Resour”再点击“Dialog”展开加号,再双击双击双击“IDC_MY...DIALOG” 四、给3个“Edit”建立3个成员变量。具体操作是:鼠标右键点击“Edit”、左键点击“建立类向导”、左键点击“Member Variables成员变量”、 左键点击“IDC_EDIT1”、左键点击“Add Variable...”、然后键盘敲“n1”、鼠标点击Variable type:下拉列表选择“int”然后单击“OK”。 再鼠标左键单击“IDC_EDIT2”、左键点击“Add Variable...”、然后键盘敲“n2”、鼠标点击Variable type:下拉列表选择“int”然后单击“OK”。 再鼠标左键单击“IDC_EDIT3”、左键点击“Add Variable...”、然后键盘敲“n3”、鼠标点击Variable type:下拉列表选择“int”然后单击“OK”。 单击“确定”回到程序主界面。 五、准备敲代码。具体操作是:用鼠标左键双击双击双击“Button1”按钮图标、再单击“OK”就打开了代码窗口。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值