c语言 换行符的用法,我可以使用换行符时为什么使用endl?

endl是一个函数,而不是关键字。

#include

int main()

{

std::cout<

return 0;

}

要了解endl的图片,您首先需要了解“函数指针”主题。

看这段代码(用C语言写)

#include

int add(int, int);

int main()

{

int (*p)(int, int); /*p is a pointer variable which can store the address

of a function whose return type is int and which can take 2 int.*/

int x;

p=add; //Here add is a function without parenthesis.

x=p(90, 10); /*if G is a variable and Address of G is assigned to p then

*p=10 means 10 is assigned to that which p points to, means G=10

similarly x=p(90, 10); this instruction simply says that p points to add

function then arguments of p becomes arguments of add i.e add(90, 10)

then add function is called and sum is computed.*/

printf("Sum is %d", x);

return 0;

}

int add(int p, int q)

{

int r;

r=p+q;

return r;

}

编译此代码,然后查看输出。

返回主题...

#include

//using namespace std;

int main()

{

std::cout<

return 0;

}

iostream文件包含在此程序中,因为iostream文件中存在cout对象的原型,而std是命名空间。 之所以使用它,是因为命名空间std中存在cout和endl的定义(库文件)。或者,您也可以在顶部使用“使用命名空间std”,因此不必在每个cout或endl之前都写“ std :: coutn << .....”。

当您在不带括号的情况下编写endl时,可以将函数endl的地址提供给cout,然后调用endl函数并更改行。这背后的原因是

namespace endl

{

printf("\n");

}

结论:在C ++之后,C代码正在运行。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值