第五十一题

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....)
题目讲解:

参考:
http://www.geeksforgeeks.org/add-two-numbers-without-using-arithmetic-operators/
int Add(int x, int y)
{
// Iterate till there is no carry
while (y != )
{
// carry now contains common set bits of x and y
int carry = x & y; // Sum of bits of x and y where at least one of the bits is not set
x = x ^ y; // Carry is shifted by one so that adding it to x gives the required sum
y = carry << ;
}
return x;
}
int Add(int x, int y)
{
if (y == )
return x;
else
return Add( x ^ y, (x & y) << );
}

第五十二题

How do you print I can print % using the printf function? (Remember % is used as a format specifier!!!)
题目讲解:

参考:
http://www.geeksforgeeks.org/how-to-print-using-printf/
printf("%%");
printf("%c", '%');
printf("%s", "%");

第五十三题

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

第五十四题

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

第五十五题

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

第五十六题

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

第五十七题

Write a C program which prints Hello World! without using a semicolon!!!
题目讲解:
#include <stdio.h>

int main()
{
while(printf(“Hello World!”)<)
{}
}








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. struts (二)

    1.运行流程 client --->tomcat  ---> webapp  -->web.xml --->filter -->struts.xml ---->na ...

  2. java重写

    1.当子类重写父类方法时,修改方法的修饰权限只能从小的范围到大的范围改变,不能从大的范围向小的范围改变,public  protected  private,[权限篇] 2.子类重写父类方法还可以修改 ...

  3. 使用Semaphore控制并发访问

    Semaphore,信号量. 用在多线程环境下对共享资源访问的一种协调机制. 当一个线程想要访问共享的资源时,这个线程需要获取Semaphore,如果Semaphore内部计数器的值大于0,Semap ...

  4. mysql 使用说明-2

    3.3.4 Retrieving Information from a Table Select 命令从表格中取回信息 SELECT what_to_select FROM which_table W ...

  5. Log4日志配置及使用

    1.log4j.xml <?xml version="1.0" encoding="gb2312" ?> <!DOCTYPE log4j:co ...

  6. OC基础(4)

    NSString 类介绍及用法 结构体成员变量 对象和方法之间的关系 对象作为方法的参数连续传递 *:first-child { margin-top: 0 !important; } body &g ...

  7. adb 命令模拟按键事件 模拟 点击 事件

    有时我们需要程序模拟按钮或点击,而手机本身又没有,哪么可以采取adb 模拟实现,最后再去实际设备去测试(前期一般都拿不到设备): 如模拟上一首,下一首,暂停等,手机上是没有的,但有些设备上是有的: / ...

  8. [ CodeVS冲杯之路 ] P1197

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1197/ 密钥的字母可以全转换为小写字母,然后一一映射,a→0,b→1,c→2,依此类推 对于密文只需将每一位减去对应密 ...

  9. [工具] 如何利用Notepad++去除重复行

    问题: 需要去除重复数据, 例如: 解决方案: 1. 打开notepad++: 2. 如果没有找到"TextFx" 选项, 需要先安装该插件. 依次打开"插件" ...

  10. git 仓库操作

    一.git 仓库从远程clone 首先要建立一个本地空目录文件比如 RuntimeJsonModel,然后: 1. git init 2. git clone https://github.com/G ...