Damn it ~

来自http://tunps.com/damn-it

今天很倒霉哦,上了实验课去图书馆借书,因为我们同学穿的是拖鞋,而我恰好看到图书馆的门口写着:拖鞋不能入内~!
就叫他在外边等我,我怕别人等急了,就搞得很匆忙,结果忙中出乱:我的借书证不见了,Damn~!
白白浪费了别人和自己的时间20+20=40分钟。下次还要到图书馆去补办,爽了~
今天看了张NCRE200604的笔试,一下是需要注意的地方。

1.  char str[]; -->错误  storage size of `str' isn't known 

2.-------------------------------------------
#include <stdio.h>
int fun(int x[],int n)
{
    static int sum=0,i;
    for(i=0;i<n;i++) sum+=x[i];
    return sum;
}
main()
{
      int a[]={1,2,3,4,5},b[]={6,7,8,9},s=0;
      s=fun(a,5)+fun(b,4);printf("%d\n",s);
}
------------------------------------------------
如果sum定义为static,结果为60,如果去掉static,结果为45。因为static的局部变量的定义,
是sum的值保持再内存中不变,第一次fun(a,5)后其值为15,fun(b,4)是在15的基础上继续加上45而得到60.

3.
#include <stdio.h>
main()
{
      int y=10;
      while(y--);
      printf("y=%d\n",y);
}

while(y--);
先看y是不是0如果不是0,就执行while loop,然后y=y-1;
当y=0;就退出while loop,然后y=y-;
所以y最后得-1;

-------------
4.
    #include
    main()
    {
          union
          {
               char ch[2];
               int d;
          }s;
          s.d=0x4321;
          printf("%x,%x\n",s.ch[0],s.ch[1]);

    }这个输出为什么不是43,21? 

s所占空间为4Byte是..
可以做int用或了个字节 ch[2];
s.d=0x4321;
addr  value
00   0x21
01   0x43
02   0x00
03   0x00
输出是21,43..涉及到汇编,以后再说。

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>