码迷,mamicode.com
首页 > 其他好文 > 详细

编程范式 episode3 and 4

时间:2015-03-12 19:08:47      阅读:144      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!