C puzzles详解】的更多相关文章

题目:http://www.gowrikumar.com/c/ 参考:http://wangcong.org/blog/archives/291 http://www.cppblog.com/smagle/archive/2010/05/27/116211.html http://blog.chinaunix.net/uid-474889-id-2397033.html 博文索引: C puzzles详解[1-5题] C puzzles详解[6-8题] C puzzles详解[9-12题] C…
第五十一题 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…