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:
请注意以下几点:
printf() prints the text as well as the value of the variable, constant etc.
printf()打印文本以及变量,常量等的值。
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输出语句
本文详细解析了C语言中printf函数的嵌套使用技巧,包括如何在printf语句中再次调用printf,以及其求值顺序和返回值特性。通过实例演示了不同嵌套printf语句的输出结果。
语句中的printf()语句&spm=1001.2101.3001.5002&articleId=107802425&d=1&t=3&u=fd145ca2fd70468ea51360dd9bcc4a5d)
6255

被折叠的 条评论
为什么被折叠?



