2016 Simulate Exam Of C

来源:互联网 发布:怎样锻炼腹肌 知乎 编辑:程序博客网 时间:2024/05/21 09:18

Open free share


  1. 一般情况下,全局变量默认初始化为0;
  2. ,
  1. What is the scope of an external variable?
    A. Whole source file in which it is defined
    B. From the point of declaration to the end of the file in which it is defined
    C. Any source file in a program
    D. From the point of declaration to the end of the file being compiled
    Answer: D

3,strcpy,stncpy等函数的越界是未定义的,而

#include <stdio.h>     int main()     {          char *str = "hello, world\n";         char *strc = "good morning\n";         strcpy(strc, str);         printf("%s\n", strc);         return 0;     } 

类似这样的使用将导致段错误(Segmentation fault (core dumped));
4,要注意到strcpy可能会一并拷贝空字符,因此使用puts,printf,strlen时便潜在了不符合猜想预期的结果;
5,
double disgusting[3][4][5][6] = {{{{0}}}};
double (*ptr)[6] = disgusting[2][1];

6,

  int i = 10, j = 2;   printf("%d\n", printf("%d %d ", i, j));  

输出结果为”10 2 5”;因为printf计量的是所打印的字符数,而绝非所打印形参的数目.
7,函数并不被允许作为结构体的成员;
8,假想把-1赋给unsigned int,
那么有:1111 1111 1111 1111 1111 1111 1111 1111;
将其强制转换为int时高位0填充,因为编译器认为这是一个正数.而使用printf的时候情况有所不同,printf并不作强制转换,它只按它的逻辑抓取字节进行输出,因此如我们有printf("%d",a);,就仍将惊喜的得到-1.
9,calloc在内存的动态存储区中分配n个长度为size的连续空间,函数返回一个指向分配起始地址的指针;如果分配不成功,返回NULL。
10,

栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等.
堆区(heap) 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收 。(而malloc,new,delete等操作的区域其实也正在此处)
静态区(static)—,全局变量和静态变量的存储是放在一块的,初始化的全局变量和静态变量在一块区域, 未初始化的全局变量和未初始化的静态变量在相邻的另一块区域。

11,有趣的是,#include<stdio.h>;只会报出警告,但实际上是程序正常运行的结果.
12,ungetc:把一个(或多个)字符f复制退回到输入流中;
13,文件的类型实际上是一种结构,这么一来,文件指针实际上是一种结构指针的事实也便呼之欲出了.
14,

    #include <stdio.h>     int main()     {          char buf[12];         stderr = stdin;         fscanf(stderr, "%s", buf);         printf("%s\n", buf);     } 

The output will be whatever user types.

0 0
原创粉丝点击