C basics

C 日记目录

C basics ................

writing Numeration 

storage   , structor space assigning

pointer,  array

 others

___________________________________-

c coding

1. define empty pointer

#define NULL  ((void*)0)

应用程序是不能访问0地址的,所以可以用0地址来表示一个空指针。

利用指针之前(例如作为形参的指针)需确保该指针有效:

if( ptr != NULL)

2, define fucntion pointer type

typedef void (*pf)(void*)

//函数名本来就是地址

____strlen()  //字符串的长度不包括 ''.

        sizeof("hello") 长度包括 ''.

__________________________________

数组和指针

int *pT;

int  a[5] = {0};

____指针当作数组用. 如果你不需要改变这个指针而要用到它为索引的数,用数组的格式来调用这个数。

aBuf[i] =pT[i];

____数组a[5],编译器编译后, 

1,a+1 为 a + 1*sizeof(int).  // a[0]+1*sizeof(a[0])

2,&a 为&a[0],//就是a

3,&a+1,  a 是数组,类型为 int(*)[5], a + sizeof(a) = a + 5*sizeof(int)

___指针能够有自己的地址: &pT. 和数组不同,上面2,&a 就是a.

___ lsearch 中的应用

 char *key = "rabbit";  //key[] wrong
http://www.cnblogs.com/aprilapril/p/4333173.html
原文地址:https://www.cnblogs.com/aprilapril/p/4176867.html