c - 为什么下面的C代码的输出是10?我的意思是为什么 printf 给出 x 作为输出?

标签 c

在 Fedora 20 桌面上使用 GCC 编译,以下代码输出 10。

int x=10;
int y=5;
printf("%d",(y,x));

最佳答案

在 C 语言中,(y,x) 表示计算 xy 并仅返回 x。例如。来自维基百科:

the comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, and then evaluates the second operand and returns this value (and type).

关于c - 为什么下面的C代码的输出是10?我的意思是为什么 printf 给出 x 作为输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22280103/

相关文章:

c# - 使用 Fopen 在 C 中读取文件并从中获取特定值

c - 我尝试打开 .dat 文件时出错

c - 一个项目中的多个文件 - C

windows下C套接字编程

javascript - 使用 NodeJS 中的变量启动 C 程序

c - C 中使用指针数组或指向指针的指针的二维数组?

c - 将 3x3 二维数组转换为 6x6 对称二维数组

c - 在C中为字符串分配内存

c++ - 将符号替换为表达式中的值并打印表达式

c - 没有malloc的C中的GET请求