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

InterView之C/CPP cal的更多相关文章

  1. InterView之C/CPP

    CPP 引用 什么是"引用"?申明和使用"引用"要注意哪些问题? 答:引用就是某个目标变量的别名(alias),对应用的操作与对变量直接操作效果完全相同.申明一 ...

  2. awesome cpp

    https://github.com/fffaraz/awesome-cpp Awesome C/C++ A curated list of awesome C/C++ frameworks, lib ...

  3. Hdu 4734 【数位DP】.cpp

    题意: 我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目给出a,b,求出0~ ...

  4. c++interview

    出自:https://github.com/huihut/interview Github    |    Docsify 简体中文    |    English 关于 本仓库是面向 C/C++ 技 ...

  5. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  6. 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码

    前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...

  7. WCF学习系列二---【WCF Interview Questions – Part 2 翻译系列】

    http://www.topwcftutorials.net/2012/09/wcf-faqs-part2.html WCF Interview Questions – Part 2 This WCF ...

  8. WCF学习系列一【WCF Interview Questions-Part 1 翻译系列】

    http://www.topwcftutorials.net/2012/08/wcf-faqs-part1.html WCF Interview Questions – Part 1 This WCF ...

  9. Amazon Interview | Set 27

    Amazon Interview | Set 27 Hi, I was recently interviewed for SDE1 position for Amazon and got select ...

随机推荐

  1. test4 结对项目

    [必做 1] 基于作业3的结果,读取一个较小的文本文件A_Tale_of_Two_Cities.txt,统计该文件中的单词的频率,并将统计结果输出到当前目录下的 Result1.txt 文件. 结对对 ...

  2. VUE 学习笔记 一 指令

    1.声明式渲染 v-bind 特性被称为指令.指令带有前缀 v-,以表示它们是 Vue 提供的特殊特性 <div id='app'> <span v-bind:title=" ...

  3. OpenStack 业务链networking-sfc介绍 (2) - 底层原理

    原文链接:https://blog.csdn.net/bc_vnetwork/article/details/65630475 1.  SFC底层实现原理 port chain和ovs driver/ ...

  4. Exp1 PC平台逆向破解 20164323段钊阳

    实验目标 学习两种方法运行代码片段,并学习如何注入运行任何Shellcode. 三个实验内容如下: 1.手工修改可执行文件,改变程序执行流程,直接跳转到getshell函数 2.利用foo函数的bof ...

  5. 苹果appID的获取方法

    1.登陆 iTunes Connect iTunes Connect 2.选择我的app 3.选择相应的应用 4.查看结果

  6. 激活IDEA,pycharm方法

    1.修改hosts文件将0.0.0.0 account.jetbrains.com添加到hosts文件最后,注意hosts文件无后缀,如果遇到无法修改或权限问题,可以采用覆盖的方法去替换hosts文件 ...

  7. lambda 、 map 、filter 、reduce 及 reversed 常用函数

    lambda 匿名函数 什么是lambda? lambda 操作符(或 lambda 函数)通常用来创建小巧的,一次性的匿名函数对象.它的基本语法如下: lambda arguments : expr ...

  8. Python简单登录密码比对

    # 源于Github的一段源码,编写的比较规范,应该是专业选手! # encoding:utf-8 __author__ = 'www.yeayee.com' # 由本站增加注释,可随意Fork.Co ...

  9. ZooKeeper学习1---简单介绍

    一.分布式协调技术 在给大家介绍ZooKeeper之前先来给大家介绍一种技术——分布式协调技术.那么什么是分布式协调技术?那么我来告诉大家,其实分布式协调技术主要用来解决分布式环境当中多个进程之间的同 ...

  10. placeholder插件详解

    placeholder插件是用来实现input或者textarea文本框显示默认文字的功能,当获得焦点时,默认文字消失.用户按删除键,把输入的字符删除掉,并失去焦点时,默认文字又出现等功能.使用此插件 ...