cal

#define DOUBLE(x) x+x ,i = 5*DOUBLE(5); i 是多少?

i 为30。 5 * 5 + 5

下面关于“联合”的题目的输出?

A

//
// Created by zhangrongxiang on 2018/3/15 11:10
// #include <stdio.h>
union {
int i;
char x[2];
} a; void main() {
a.x[0] = 10;
a.x[1] = 1;
printf("%d", a.i);
}

266 低位低地址,高位高地址,内存占用情况是Ox010A

B

//
// Created by zhangrongxiang on 2018/3/15 11:13
//
#include <stdio.h> int main() {
union { /*定义一个联合*/
int i;
struct { /*在联合中定义一个结构*/
char first;
char second;
} half;
} number;
number.i = 0x4241; /*联合成员赋值*/
printf("%c%c\n", number.half.first, number.half.second);//AB
number.half.first = 'a'; /*联合中结构成员赋值*/
number.half.second = 'b';
printf("%x\n", number.i);//6261
return 0;
}

AB(0x41对应'A',是低位;Ox42对应'B',是高位)6261(number.i和number.half共用一块地址空间)

已知strcpy的函数原型:char *strcpy(char *strDest, const char *strSrc)其中strDest 是目的字符串,strSrc 是源字符串。不调用C++/C 的字符串库函数,请编写函数 strcpy。

Mystrcpy

//
// Created by zhangrongxiang on 2018/3/15 11:18
// File 4
// /*
编写strcpy函数(10分)
已知strcpy函数的原型是
char *strcpy(char *strDest, const char *strSrc);
其中strDest是目的字符串,strSrc是源字符串。
(1)不调用C++/C的字符串库函数,请编写函数 strcpy
(2)strcpy能把strSrc的内容复制到strDest,为什么还要char * 类型的返回值?
答:为了 实现链式表达式。 // 2分
例如 int length = strlen( strcpy( strDest, “hello world”) );
*/ #include <assert.h>
#include <stdio.h> char *Mystrcpy(char *strDest, const char *strSrc) {
assert((strDest != NULL) && (strSrc != NULL));// 2分
char *address = strDest; // 2分
while ((*strDest++ = *strSrc++) != '\0');// 2分
return address; // 2分
} int main() {
char desc[20] = {0};
char src[20] = "Hello World";
Mystrcpy(desc, src);
printf("%s\n", desc);
return 0;
}

Mystrlen

//
// Created by zhangrongxiang on 2018/3/15 16:17
// File 7
// #include <stdio.h>
#include <assert.h> int Mystrlen(const char *str) { // 输入参数const
assert(str != NULL); // 断言字符串地址非0
int len = 0;
while ((*str++) != '\0') {
len++;
}
return len;
} int main() {
char str[] = "Hello World";
printf("%d\n", Mystrlen(str));//11
printf("%d\n", (int) sizeof(str));//12
}

There are twoint variables: a and b, don’t use “if”, “? :”, “switch”or other judgementstatements, find out the biggest one of the two numbers.

( ( a + b ) + abs( a - b ) ) / 2

如何打印出当前源文件的文件名以及源文件的当前行号?

cout << __FILE__ ;
cout << __LINE__ ;
//__FILE__和__LINE__是系统预定义宏,这种宏并不是在某个文件中定义的,而是由编译器定义的

main主函数执行完毕后,是否可能会再执行一段代码,给出说明?

可以,可以用_onexit 注册一个函数,它会在main 之后执行int fn1(void), fn2(void), fn3(void),fn4 (void);

void main( void ){
  String str("zhanglin");
  _onexit( fn1 );
  _onexit( fn2 );
  _onexit( fn3 );
  _onexit( fn4 );
  printf( "This is executed first.\n" );
} int fn1(){
  printf( "next.\n" );
  return 0;
} int fn2(){
  printf( "executed " );
  return 0;
} int fn3(){
  printf( "is " );
  return 0;
} int fn4(){
  printf( "This " );
  return 0;
}

如何判断一段程序是由C编译程序还是由C++编译程序编译的?

#ifdef __cplusplus
  cout << "c++";
#else
  cout << "c";
#endif

最新文章

  1. 一例完整的websocket实现群聊demo
  2. Spring3系列7- 自动扫描组件或Bean
  3. 有两个数a,b,请写一个函数交换a,b
  4. BZOJ 1101 Zap(莫比乌斯反演)
  5. POJ - 1185 炮兵阵地 (状态压缩)
  6. IE6滤镜在实战测试中能让父层里面的子元素产生阴影
  7. angularJS入门笔记
  8. Deep Reinforcement Learning for Dialogue Generation 论文阅读
  9. 008_ssl Certificate Pinning
  10. UVa - 10341
  11. sql数据库连接字符串在APP.config配置文件内的两种写法
  12. Python3基础 response.getcode 得到http的状态 200表示正常
  13. 关于 svn
  14. MyForm_参考django的Form组建
  15. mybatis plugin作为一款优秀的mybatis跳转插件
  16. 接口自动化(三)--读取json文件中的数据
  17. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
  18. HihoCoder - 1236 Scores (五维偏序,分块+bitset)
  19. 『AngularJS』ngValue
  20. 天猫首页迷思之-jquery实现整个div的懒加载(2)-插件面向对象化-闭包和原型的实例

热门文章

  1. Spring 之 IOC
  2. linux mongodb开机启动(服务的方式)
  3. 支付宝PC网站接口对接
  4. 浅谈 温故知新——HTML5!
  5. GO语言官方中文教程!
  6. python 杂谈
  7. BZOJ 2388--旅行规划(分块&amp;单调栈&amp;二分)
  8. (二)Python 装饰器
  9. 新版 iPad Pro 弯了,苹果表示这是正常现象……
  10. Leetcode 88 合并两个有序数组 Python