标签:
episode 3
--storage structure. ampersand operate with asterisk
--library function
episode 4
--generic function 泛型函数
swap(void* pa,void*pb,int size);
-----ampersand and asterisk
the original types does not matter much, the pointer does.
when a pointer is operated with a intergral, just remember to transit the intergral into the same type length with the pointer.
--big endian, little endian(most linux)
-----array
int array[10];
array = &arry[0];
array+k = &array[k]; //k 进行指针运算,要扩展成array同类型长度
*array = array[0];
*(array+k)=array[k];
*(array-4)=8;
array[-4] = 8;//there is no bond check in C, so it will put 8 at the corresponding address.This is not good //code, the result is unsure, it may crush.
-------liabrary function
--strdup("adm"); //as it shows itself, only valid to string type.
memcpy function,return an adress pointed at heap which store"adm"(with string end sign).
--strcpy(pAim, "4021");
"4021" is copied into the memory started at address pAim.
--memcpy(void*to,void*from,int size)
copy designated size to the memory.
------swap(void* pa,void*pb,int size);
swap(void* pa,void*pb,int size)
{
char temp[size];
memcpy(temp,pa,size);
memcpy(pa,pb,size);
memcpy(pb,temp,size);
}
标签:
原文地址:http://www.cnblogs.com/aprilapril/p/4333173.html