无法理解以下代码的输出
Unable to understand output of the below code
下面给出的代码是我老师问的。
这只是为了测试谁可以在没有 运行 代码的情况下找出输出。
使用 Turbo C++ 进行编译。
我无法理解在函数调用中递增和递减是如何发生的,天气值在下面的代码中是如何从左到右或从右到左传递的。
#include<stdio.h>
#include<conio.h>
int main(){
char c[]="hello";
char *p;
clrscr();
p=&c[0];
printf("%c %c %c ",++*p,*++p,*p++);
puts(c);
getchar();
return 0;
}
根据我的说法,输出是:
艾尔
埃姆洛
但是当它编译并且 运行 我得到:
立方米
毒芹素
为什么会发生这种情况是值是从右向左传递还是其他原因?
提前致谢。
运行 OP 发布的代码导致:
m l h hemlo
然而,编译器输出为:
gcc -ggdb -Wall -o "untitled" "untitled.c" -lncurses -lrt -lpthread -lm -lgmp
untitled.c: In function ‘main’:
untitled.c:11:32: warning: operation on ‘p’ may be undefined [-Wsequence-point]
printf("%c %c %c ",++*p,*++p,*p++);
~^~
untitled.c:11:32: warning: operation on ‘p’ may be undefined [-Wsequence-point]
Compilation finished successfully.
由于未定义的问题,实际输出可能是任何东西
下面给出的代码是我老师问的。 这只是为了测试谁可以在没有 运行 代码的情况下找出输出。 使用 Turbo C++ 进行编译。
我无法理解在函数调用中递增和递减是如何发生的,天气值在下面的代码中是如何从左到右或从右到左传递的。
#include<stdio.h>
#include<conio.h>
int main(){
char c[]="hello";
char *p;
clrscr();
p=&c[0];
printf("%c %c %c ",++*p,*++p,*p++);
puts(c);
getchar();
return 0;
}
根据我的说法,输出是: 艾尔 埃姆洛
但是当它编译并且 运行 我得到: 立方米 毒芹素 为什么会发生这种情况是值是从右向左传递还是其他原因?
提前致谢。
运行 OP 发布的代码导致:
m l h hemlo
然而,编译器输出为:
gcc -ggdb -Wall -o "untitled" "untitled.c" -lncurses -lrt -lpthread -lm -lgmp
untitled.c: In function ‘main’:
untitled.c:11:32: warning: operation on ‘p’ may be undefined [-Wsequence-point]
printf("%c %c %c ",++*p,*++p,*p++);
~^~
untitled.c:11:32: warning: operation on ‘p’ may be undefined [-Wsequence-point]
Compilation finished successfully.
由于未定义的问题,实际输出可能是任何东西