首页 > 其他 > 详细

编程范式 episode3 and 4

时间:2015-03-12 19:08:07      阅读:327      评论:0      收藏:0      [点我收藏+]

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);
}

 

编程范式 episode3 and 4

原文:http://www.cnblogs.com/aprilapril/p/4333173.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!