*用C ++ VS precedence [英] * Vs ++ precedence in C
本文介绍了*用C ++ VS precedence的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能够理解下面的C code的输出:
#包括LT&;&stdio.h中GT;
主要()
{
字符*的东西=东西;
的printf(%C,*事++); //小号
的printf(%C,*的东西); //Ø
的printf(%C,* ++的东西); //米
的printf(%C,*事++); //米
}
请帮忙:)
解决方案
//主入口点
INT主(INT ARGC,CHAR *的argv [])
{
字符*的东西=东西; //增加一些一种类型的宽度(炭)的值,然后
//返回previous值它指出,也可以用作
//为printf的输入。
//结果是:打印的,现在的东西指向O。
的printf(%C,*事++); //打印characer以包含在指针的东西地址
//结果是:打印'O'
的printf(%C,*的东西); //由一种类型的宽度递增指针的东西的地址值
//类型为char,所以一个字节增加地址值。然后
//在指针的东西所产生的地址打印的字符。
//结果是:现在的东西在指向M,打印M
的printf(%C,* ++的东西); //增加一些一种类型的宽度(炭)的值,然后
//返回previous值它指出,也可以用作
//为printf的输入。
//结果是:打印的,现在的东西指向O。
的printf(%C,*事++);
}
结果:
SOMM
I am not able to understand the output of the following C code :
#include<stdio.h>
main()
{
char * something = "something";
printf("%c", *something++); // s
printf("%c", *something); // o
printf("%c", *++something); // m
printf("%c", *something++); // m
}
Please help :)
解决方案
// main entrypoint
int main(int argc, char *argv[])
{
char * something = "something";
// increment the value of something one type-width (char), then
// return the previous value it pointed to, to be used as the
// input for printf.
// result: print 's', something now points to 'o'.
printf("%c", *something++);
// print the characer at the address contained in pointer something
// result: print 'o'
printf("%c", *something);
// increment the address value in pointer something by one type-width
// the type is char, so increase the address value by one byte. then
// print the character at the resulting address in pointer something.
// result: something now points at 'm', print 'm'
printf("%c", *++something);
// increment the value of something one type-width (char), then
// return the previous value it pointed to, to be used as the
// input for printf.
// result: print 's', something now points to 'o'.
printf("%c", *something++);
}
Result:
somm
这篇关于*用C ++ VS precedence的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文