卸了个简单的程序,求的是1+2+2^2+2^3+2^4+……+2^n,,,
编译无问题,结果是负的。。绝对值还很大。。。
都已经unsigned了!!!
代码: 全选
#include <stdio.h>
main()
{
unsigned int i,n,res=1;
scanf("%d",&n);
n++;
for (i=1;i<=n;i++)
res*=2;
res-=1;
printf("%d\n",&res);
}
yangsos123@AlanAllen:~/C/Part-入门$ gcc ex6.c -o ex6.out
ex6.c: In function ‘main’:
ex6.c:10: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘unsigned int *’
yangsos123@AlanAllen:~/C/Part-入门$ ./ex6.out
2
-1074561196