第五十一题

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. Ubuntu各个版本的介绍

    Ubuntu的版本比较多,而且基于ubuntu的衍生版也很多,让人容易混淆,也让很多人不知道自己适合哪一个,在这里简单比较一下ubuntu的各个版本的特点: 介绍ubuntu版本之前先说一说与ubun ...

  2. 根据职位名,自动生成jd

    代码本身就是最好的解释,不赘述. 文本聚类输出: cluster.py #!/usr/bin/env python # coding=utf-8 import jieba,re from gensim ...

  3. Oracle迁移MySQL笔记

    1,--在oracle代表注释 ,mysql/* */,# 2,|| oracle里面是表示连接符号,比如 A||B 那么就是AB 3,databaseLink创建好之后,比如名字为db_link_b ...

  4. DXperience-11.1.5 破解

    将DXPerience_11.1.5_Crack里的所有文件粘贴到DXperience-11.1.5的bin文件夹下,然后在cmd运行register.bin

  5. JDK环境变量中dt.jar、tools.jar等变量值的作用

    变量名:CLASSPATH 变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; tools.jar: 工具类 库,它跟我们程序中用到的 基础 ...

  6. T450设置插入USB鼠标时自动禁用触摸板

    刚入手T450,打字时经常碰到触摸板,很是恼火,于是求助万能的度娘,找了卡饭基佬的教程,实测可行,大家可以试试.<win7下如何设置插入USB鼠标时自动禁用触摸板>,地址:www.kafa ...

  7. python实现线程池

    线程池 简单线程池 import queue import threading import time class ThreadPool(object): #创建线程池类 def __init__(s ...

  8. MSSQL中的随机函数

    随机函数:rand()在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会 ...

  9. Winista.Text.HtmlParser; 获取html

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  10. Problem 2195 检查站点(普通树构造)(Vector)

    Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description 在山上一共有N个站点需要检查,检查员从山顶出发去各个站点进行检 ...