C puzzles详解【38-45题】】的更多相关文章

第五十一题 Write a C function which does the addition of two integers without using the '+' operator. You can use only the bitwise operators.(Remember the good old method of implementing the full-adder circuit using the or, and, xor gates....) 题目讲解: 参考:ht…
第四十六题 What does the following macro do? #define ROUNDUP(x,n) ((x+n-1)&(~(n-1))) 题目讲解: 参考:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=814501 用于内存对齐,n为2的幂. 第四十七题 Most of the C programming books, give the following example for the definitio…
第三十八题 What is the bug in the following program? #include <stdlib.h> #include <stdio.h> #define SIZE 15 int main() { int *a, i; a = malloc(SIZE*sizeof(int)); ; i<SIZE; i++) *(a + i) = i * i; ; i<SIZE; i++) printf("%d\n", *a++);…
第三十四题 The following times. But you can notice that, it doesn't work. #include <stdio.h> int main() { int i; ; ; i < n; i-- ) printf("-"); ; } Well fixing the above code is straight-forward. To make the problem interesting, you have to f…
第三十一题 The following is a simple C program to read and print an integer. But it is not working properly. What is(are) the mistake(s)? #include <stdio.h> int main() { int n; printf("Enter a number:\n"); scanf("%d\n",n); printf(&quo…
第二十六题(不会) The following is a simple program which implements a minimal version of banner command available on most *nix systems. Find out the logic used in the program. #include<stdio.h> #include<ctype.h> char t[]={ ,,,,,,,,,, ,,,,,,,,,, ,,,,,…
第二十一题 What is the potential problem with the following C program? #include <stdio.h> int main() { ]; printf("Enter the string:"); scanf("%s",str); printf("You entered:%s\n",str); ; } 题目讲解: 易造成数组越界,scanf改成如下形式比较保险 scanf(…
第十六题 The following is a small C program split across files. What do you expect the output to be, when both of them compiled together and run? File1.c ]; File2.c extern int *arr; int main() { arr[] = ; ; } 题目讲解: 编译完运行发生段错. File1.c中声明的是个数组,File2.c中声明的是…
第十三题 int CountBits(unsigned int x) { ; while(x) { count++; x = x&(x-); } return count; } 知识点讲解 位运算 关于位运算的一些例子参考: http://www.ugcs.caltech.edu/~wnoise/base2.html 题目讲解 x&(x-1)常见的两种应用: 1)计算x二进制形式中1的个数,每循环一次,将x二进制形式最右边的1变成0: 2)判断x是否是2的幂,若x&(x-1)==0…
第九题 #include <stdio.h> int main() { float f=0.0f; int i; ;i<;i++) f = f + 0.1f; if(f == 1.0f) printf("f is 1.0 \n"); else printf("f is NOT 1.0\n"); ; } 知识点讲解: 浮点寄存器 浮点寄存器是FPU的组成部分.硬件架构不同,浮点寄存器的个数和位数也不同.X86架构的浮点寄存器有: 1)8个80位的数据…