2013年3月31日
摘要: 1. 比较两数大小相减之后看符号位#defineCMP(a,b)(((long)((a)-(b))) >> 31) - (((long)((b)-(a))) >> 31)返回1表示a>b,返回-1表示a<b,返回0表示a==b2. 求两数最大值 阅读全文
posted @ 2013-03-31 22:50 chenkkkabc 阅读(300) 评论(0) 推荐(0) 编辑
摘要: 1. 转换成二进制进行加法int bit_add(int a ,int b){ int carry = a & b; int no_carry_sum = a ^ b; if (carry != 0) { return bit_add(carry << 1, no_carry_sum); } else{ return no_carry_sum; } return 0;}2. 利用数组下标特性int arr_idx_add(int a, int b){ char* c = (char*) a; return (int)&c[b];} 阅读全文
posted @ 2013-03-31 19:27 chenkkkabc 阅读(212) 评论(0) 推荐(0) 编辑
摘要: 写段代码测试一下变量的内存分布:#include <cstdlib>#include <cstdio>char bss_global;char rw_data_global = 0;const char ro_data1 = 0;static char rw_data_static = 0;int main() { static char bss_static; char stack1; char stack2[] = {"Hello world!"}; const char stack3 = 0; const char* ro_data2 = &q 阅读全文
posted @ 2013-03-31 12:59 chenkkkabc 阅读(168) 评论(0) 推荐(0) 编辑