c语言printf输出语句_C语言中另一个printf()语句中的printf()语句

c语言printf输出语句

A printf() function is a standard library function, that is used to print the text and value on the standard output screen. Here, we will evaluate the expression – where a printf() is used within another printf() statement.

printf()函数是一个标准库函数,用于在标准输出屏幕上打印文本和值。 在这里,我们将评估表达-在一个printf()是另外的printf()语句中使用。

Consider the statement:

考虑以下语句:

    printf ("%d", printf ("Hello"));

Note these points:

请注意以下几点:

  1. printf() prints the text as well as the value of the variable, constant etc.

    printf()打印文本以及变量,常量等的值。

  2. printf() returns an integer value that is the total number of printed characters including spaces, carriage return, line feed etc.

    printf()返回一个整数值,该值是已打印字符的总数,包括空格,回车,换行等。

Evaluation of the above written statement:

评估以上书面声明:

printf() function evaluates from right to left, thus printf("Hello") will be evaluated first, that will print "Hello" and printf("Hello") will return the total number of printed character that is 5 and then the output of this printf("Hello") after printing "Hello" will be 5.

printf()函数从右到左求值,因此将首先对printf(“ Hello”)进行求值,这将打印“ Hello”,而printf(“ Hello”)将返回打印的字符总数5 ,然后输出打印“ Hello”之后,此printf(“ Hello”)的值为5

Thus, finally, the output of the above-written statement will be: "Hello5".

因此,最后,上述语句的输出为: “ Hello5”

Example:

例:

#include <stdio.h>

int main(void)
{
	printf("%d", printf ("Hello"));
	return 0;
}

Output

输出量

Hello5

在printf()语句中使用多个printf() (Using more than one printf() within printf() statement )

Consider the following statement:

考虑以下语句:

    printf ("%d%d", printf ("Hello") , printf ("friends"));

Evaluation:

评价:

As we said above that the printf() arguments evaluates from right to left, thus, printf("Friends") will be evaluated first and return 7, after that statement printf("Hello") will be evaluated and return 5. Thus, the final output will be "friendsHello57".

就像我们上面说过的, printf()参数从右到左求值,因此,将首先对printf(“ Friends”)进行求值并返回7 ,然后对该语句printf(“ Hello”)进行求值并返回5 。 因此,最终输出将为“ friendsHello57”

Example:

例:

#include <stdio.h>

int main(void)
{
	printf ("%d%d", printf ("Hello"), printf ("Friends"));
	return 0;
}

Output

输出量

FriendsHello57


翻译自: https://www.includehelp.com/c-programs/printf-statement-within-another-printf-statement-in-c.aspx

c语言printf输出语句

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值