第五十一题

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. 怎么安装phpcms?PHPCMS V9安装图文教程

    Phpcms是国内领先的网站内容管理系统, 同时也是一个开源的PHP开发框架.PHPCMS V9目前已提供文章.图片.下载等内容模型,在此基础上可非常方便的扩展出信息.房产.交友.点评等功能.已有的模 ...

  2. Java将一段逗号分割的字符串转换成一个数组

    String 类:String 类代表字符串.Java 程序中的所有字符串字面值都作为此类的实例实现.字符串是常量,它们的值在创建之后不能更改.字符串缓冲区支持可变的字符串.因为 String 对象是 ...

  3. 【转】group by多个字段理解

    来源:http://uule.iteye.com/blog/1569262 首先group by 的简单说明: group by 一般和聚合函数一起使用才有意义,比如 count sum avg等,使 ...

  4. nyoj 93 汉诺塔(三)

    点击打开链接 汉诺塔(三) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 在印度,有这么一个古老的传说:在世界中心贝拿勒斯(在印度北部)的圣庙里,一块黄铜板上插着三根宝 ...

  5. maven与git

    ================================================== maven的作用 ======================================== ...

  6. 如何隐藏storyboard中的top bar

    在navigation bar中是没有设置它的隐藏和显示的属性的 那么究竟在什么地方呢,当在它自身的属性中没有找到的情况下,那么就只能去包含它的容器中去寻找了,结果果然找到了.在view的第四个选择器 ...

  7. iOS UIButton 设置图片文字垂直排列

    后面经过测试,如果button的文字长度变更,会导致图片位置变化,经过多次修改UIEdgeInsets的值也没有达到期望效果,最终采用集成UIButton类,重写layoutSubviews函数实现, ...

  8. 《你不知道的JavaScript》一

    1.编译原理 尽管通常将 JavaScript 归类为"动态"或"解释执行"语言,但事实上它是一门编译语言. 在传统编译语言的流程中,程序中的一段源代码在执行之 ...

  9. [Mongo] 简单的操作命令

    1. 连接服务器: mongo 2. 连接数据库 use dbname 3. 查询所有集合的名字 db.getCollectionNames() 4. 查询某集合的数据 db.collection.f ...

  10. 用Asroute解决复杂状态切换问题

    项目地址:https://github.com/boycy815/asroute 首先明确几个概念 状态: 很多情况下,一个复杂的UI组件可能会有很多种不同的“状态”,不同的“状态”下组件本身对外界会 ...