“知不知,上;不知知,病。圣人不病,以其病病。夫唯病病,是以不病。”
1 find out the wrong definition of array.
A int A[] B int A[]={1,2,3,4,5};
C int A[10]={0} D int A[10]
2 give description between big endian and little endian (字节存储次序)And write a macro to convert a 16bit integer to big endian.
/* Note:Your choice is C IDE */
#include "stdio.h"
#define MAX(a,b) ((a)>(b))?(a):(b)
#define CONVERT_TO_BIGENDIAN(x) {char temp=(char)(x&0x00FF);/
*((char*)(&x))=(char)((x&0xFF00)>>8);/
*((char*)(&x)+1)=temp;}
main()
{
int A[]={1,2,3,4,5};
int B[10]={0};
int C[10];
int a1=0x1234;
printf("%d/n",sizeof(int));/*2*/
printf("%x/n",a1);/*1234*/
printf("%x/n",*(char*)(&a1));/*34*/
printf("%x/n",*((char*)(&a1)+1));/*12*/
printf("%x/n",(char)((a1&0xFF00)>>8));/*34*/
printf("%x/n",(char)(a1&0x00FF));/*34*/
CONVERT_TO_BIGENDIAN(a1)/*3434*/
printf("%x",a1);
return;
}
注:
A N S I标准说明了五个预定义的宏名。它们是:
_ L I N E _ (两个下划线),对应%d
_ F I L E _ 对应%s
_ D A T E _ 对应%s
_ T I M E _ 对应%s
_ S T D C _
使用宏跟踪调试
3 tell the literal meaning of words below.
static:
C : static func;static global variant ;local static variant:控制存储方式,控制可见性和链接类型,
C++ :static member func and static member variant:
union: 多个成员变量的集合,但同一时间只存储一个成员变量,空间大小为最大的一个成员占有的空间
const:
C : 限定一个变量不容许被改变的qualifier,
C++ :cosnt 可修饰对象/成员函数/参数/返回值,一个左结合的类型修饰符
void *:无类型指针,可以指向任何类型的数据,无需强制类型转换地赋给其它类型的指针
void真正发挥的作用在于:void不能代表一个真实的变量,类似面向对象中的抽象基类
(1) 对函数返回的限定;如果函数没有返回值,那么应声明为void类型(在C语言中,凡不加返回值类型限定的函数,就会被编译器作为返回整型值处理)
(2) 对函数参数的限定。如果函数无参数,那么应声明其参数为void.如果函数的参数可以是任意类型指针,那么应声明其参数为void*
enum:
enum 枚举名{ 枚举值表 }; 同结构和联合一样,即先定义后说明,同时定义说明或直接说明.
枚举值是常量,不是变量。不能在程序中用赋值语句再对它赋值.枚举元素本身由系统定义了一个表示序号的数值,从0开始顺序定义为0,1,2…。
extern: 置于变量或者函数前,以标示变量或者函数的定义在别的文件中,提示编译器遇到此变量和函数时在其他模块中寻找其定义。
4 correct
char fun1(char* s)
{ char* temp=s; char ret=temp[1]; return ret;};
char * s1=”abcd”;
char (*pFunc)(char*)=fun1;
printf(“%c/n”,pFunc(s1)); //b