第五十一题

  1. 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....)
  1. 题目讲解:
  2. 参考:
    http://www.geeksforgeeks.org/add-two-numbers-without-using-arithmetic-operators/
  1. int Add(int x, int y)
  2. {
  3. // Iterate till there is no carry
  4. while (y != )
  5. {
  6. // carry now contains common set bits of x and y
  7. int carry = x & y;
  8.  
  9. // Sum of bits of x and y where at least one of the bits is not set
  10. x = x ^ y;
  11.  
  12. // Carry is shifted by one so that adding it to x gives the required sum
  13. y = carry << ;
  14. }
  15. return x;
  16. }
  1. int Add(int x, int y)
  2. {
  3. if (y == )
  4. return x;
  5. else
  6. return Add( x ^ y, (x & y) << );
  7. }

第五十二题

  1. How do you print I can print % using the printf function? (Remember % is used as a format specifier!!!)
  1. 题目讲解:
  2. 参考:
    http://www.geeksforgeeks.org/how-to-print-using-printf/
  1. printf("%%");
  2. printf("%c", '%');
  3. printf("%s", "%");
  1.  

第五十三题

  1. What's the difference between the following two C statements?
  2. const char *p;
  3. char* const p;
  1. 题目讲解:
    const char *p:
    p指向的值只读;
    char* const p:
    p的值只读;

第五十四题

  1. What is the difference between memcpy and memmove?
  1. 题目讲解:
    对重叠区域(overlapping regions)的处理有区别。

第五十五题

  1. What is the format specifiers for printf to print double and float values?
  1. 题目讲解:
    double: %lf
    float: %f

第五十六题

  1. Write a small C program to determine whether a machine's type is little-endian or big-endian.
  1. 题目讲解:
    参考:
    http://www.geeksforgeeks.org/little-and-big-endian-mystery/
  1. unsigned int determine_endian()
  2. {
  3. unsigned int i = ;
  4. char *c = (char *)&i;
  5. if (*c)
  6. return ;//little endian
  7. else
  8. return ;//big endian
  9. }

第五十七题

  1. Write a C program which prints Hello World! without using a semicolon!!!
  1. 题目讲解:
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. while(printf(“Hello World!”)<)
  6. {}
  7. }
  1.  
  1.  
  1.  
  1.  
  1.  
  1.  
  1.  
  1.  

C puzzles详解【51-57题】的更多相关文章

  1. C puzzles详解【46-50题】

    第四十六题 What does the following macro do? #define ROUNDUP(x,n) ((x+n-1)&(~(n-1))) 题目讲解: 参考:http:// ...

  2. C puzzles详解【38-45题】

    第三十八题 What is the bug in the following program? #include <stdlib.h> #include <stdio.h> # ...

  3. C puzzles详解【34-37题】

    第三十四题 The following times. But you can notice that, it doesn't work. #include <stdio.h> int ma ...

  4. C puzzles详解【31-33题】

    第三十一题 The following is a simple C program to read and print an integer. But it is not working proper ...

  5. C puzzles详解【26-30题】

    第二十六题(不会) The following is a simple program which implements a minimal version of banner command ava ...

  6. C puzzles详解【21-25题】

    第二十一题 What is the potential problem with the following C program? #include <stdio.h> int main( ...

  7. C puzzles详解【16-20题】

    第十六题 The following is a small C program split across files. What do you expect the output to be, whe ...

  8. C puzzles详解【13-15题】

    第十三题 int CountBits(unsigned int x) { ; while(x) { count++; x = x&(x-); } return count; } 知识点讲解 位 ...

  9. C puzzles详解【9-12题】

    第九题 #include <stdio.h> int main() { float f=0.0f; int i; ;i<;i++) f = f + 0.1f; if(f == 1.0 ...

随机推荐

  1. Java多线程之捕获异常

    1.主线程不能捕获到子线程的异常 package Thread.Exection; import java.util.concurrent.ExecutorService; import java.u ...

  2. 玄机论坛Socket类库源码 当前版本 2.6.3 更新日期:10-09/2015 z

    http://bbs.msdn5.com/thread-27-1-1.html 本类库采用TcpLister,TcpClient高度封装, 采用NetworkStream进行异步模式读取数据. 采用S ...

  3. sql server 2008 r2 中的oracle发布使用笔记

    sql server 2008 r2 中的oracle发布功能,能够将oracle数据库作为发布服务器,将oracle中的数据自动同步到sql server 数据库中,在新建oracle发布前确保sq ...

  4. 立体匹配:关于Middlebury提供的源码的简化后的结构

  5. [SQL]断开并更改数据库名

    EXEC sp_dboption 'my', 'Single User', 'TRUE' EXEC sp_renamedb 'my', 'mycrjtest' EXEC sp_dboption 'my ...

  6. 如何在组件(Component中)模拟用户控件(UserControl)中FindForm()?

    using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentM ...

  7. C Primer Plus(第五版)6

    第 6 章 C 控制语句 : 循环 在本章中你将学习下列内容 已经多次学过,没怎么标注 · 关键字: for while do while · 运算符: < > >= <= ! ...

  8. Hbase基础操作

    $HBASE_HOME/bin/hbase org.apache.hadoop.hbase.mapreduce.RowCounter 'tablename'

  9. 面向对象的ExtJS场景开发

    写ExtJS已经3各月了,项目中临时学的,主要参考ExtJS 的文档学习,推荐一款JS开发工具Aptana Studio 3. 大概说一下开发ExtJS的准备: 1.下载Extjs(目前有4.x我使用 ...

  10. 转载:LoadRunner11-遇到问题及解决办法

    转自:http://4951507.blog.51cto.com/4941507/1108733 1.LoadRunner超时错误:在录制Web服务器端,如果超过120秒服务器协议脚本回放时超时情况经 ...