C puzzles详解【51-57题】
第五十一题
- 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....)
- 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!!!)
- 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.
- 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题】的更多相关文章
- C puzzles详解【46-50题】
第四十六题 What does the following macro do? #define ROUNDUP(x,n) ((x+n-1)&(~(n-1))) 题目讲解: 参考:http:// ...
- C puzzles详解【38-45题】
第三十八题 What is the bug in the following program? #include <stdlib.h> #include <stdio.h> # ...
- C puzzles详解【34-37题】
第三十四题 The following times. But you can notice that, it doesn't work. #include <stdio.h> int ma ...
- C puzzles详解【31-33题】
第三十一题 The following is a simple C program to read and print an integer. But it is not working proper ...
- C puzzles详解【26-30题】
第二十六题(不会) The following is a simple program which implements a minimal version of banner command ava ...
- C puzzles详解【21-25题】
第二十一题 What is the potential problem with the following C program? #include <stdio.h> int main( ...
- C puzzles详解【16-20题】
第十六题 The following is a small C program split across files. What do you expect the output to be, whe ...
- C puzzles详解【13-15题】
第十三题 int CountBits(unsigned int x) { ; while(x) { count++; x = x&(x-); } return count; } 知识点讲解 位 ...
- 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 ...
随机推荐
- Java多线程之捕获异常
1.主线程不能捕获到子线程的异常 package Thread.Exection; import java.util.concurrent.ExecutorService; import java.u ...
- 玄机论坛Socket类库源码 当前版本 2.6.3 更新日期:10-09/2015 z
http://bbs.msdn5.com/thread-27-1-1.html 本类库采用TcpLister,TcpClient高度封装, 采用NetworkStream进行异步模式读取数据. 采用S ...
- sql server 2008 r2 中的oracle发布使用笔记
sql server 2008 r2 中的oracle发布功能,能够将oracle数据库作为发布服务器,将oracle中的数据自动同步到sql server 数据库中,在新建oracle发布前确保sq ...
- 立体匹配:关于Middlebury提供的源码的简化后的结构
- [SQL]断开并更改数据库名
EXEC sp_dboption 'my', 'Single User', 'TRUE' EXEC sp_renamedb 'my', 'mycrjtest' EXEC sp_dboption 'my ...
- 如何在组件(Component中)模拟用户控件(UserControl)中FindForm()?
using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentM ...
- C Primer Plus(第五版)6
第 6 章 C 控制语句 : 循环 在本章中你将学习下列内容 已经多次学过,没怎么标注 · 关键字: for while do while · 运算符: < > >= <= ! ...
- Hbase基础操作
$HBASE_HOME/bin/hbase org.apache.hadoop.hbase.mapreduce.RowCounter 'tablename'
- 面向对象的ExtJS场景开发
写ExtJS已经3各月了,项目中临时学的,主要参考ExtJS 的文档学习,推荐一款JS开发工具Aptana Studio 3. 大概说一下开发ExtJS的准备: 1.下载Extjs(目前有4.x我使用 ...
- 转载:LoadRunner11-遇到问题及解决办法
转自:http://4951507.blog.51cto.com/4941507/1108733 1.LoadRunner超时错误:在录制Web服务器端,如果超过120秒服务器协议脚本回放时超时情况经 ...