mark一个与printf相关的知识点

int optqueue()
{
	SQueue queue = creatQueue(12, "hello world");
	printf("len of queue%d\nget fornt %c \nlen of queue%d\n", queue->len, delQueue(queue), queue->len);
	//printf("len of queue%d\n", queue->len);
	//printf("get fornt %c \n", delQueue(queue));
	//printf("len of queue%d\n", queue->len);

}

代码如上,输出如下

len of queue10 
get fornt h 
len of queue11

瞬间抑郁

这个printf有个执行顺序和取值顺序,我猜如此;

验证:

代码如下

	int a = 1, b = 2, c = 3;
	printf("%d %d %d\n", a, b, c);
	printf("%d %d %d\n", a++, a++, a++);
	a = 1;
	printf("%d %d %d\n", a, a++, a);
	return 0; 

看结果:

1 2 3
3 2 1 
2 1 2

更加抑郁了。。。

所以,这是一个无解的东西,由于编译平台的不同,其输出结果会不同,可是似乎很多笔试题都会考察到这个,但是其只靠查执行顺序,不考察打印顺序,因此,如果以后需要打印多个数据,别偷懒,像这样:

	//printf("len of queue%d\n", queue->len);
	//printf("get fornt %c \n", delQueue(queue));
	//printf("len of queue%d\n", queue->len);

执行顺序如下代码:

	int a = 1, b = 2, c = 3;
	printf("%d %d %d\n", a=a+c, b=c-a, c++);
	printf("%d\n", a);
	printf("%d\n", b);
	printf("%d\n", c);
	return 0; 

结果:

5 3 3 
5
3 
4

可以看出是从右向左执行 的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值