Programming Paradigm Episode3 and 4

Source: Internet
Author: User

Episode 3

--storage structure. Ampersand operate with Asterisk

--library function

Episode 4

--generic function Generic Functions

Swap (void* pa,void*pb,int size);

-----Ampersand and asterisk

The original types does not matter much, the pointer does.

When a pointer was operated with a intergral, just remember to transit the intergral into the same type length with the POI Nter.

--big endian, Little endian (most Linux)

-----array

int array[10];

Array = &arry[0];

Array+k = &array[k]; K for pointer operation, to expand to array of the same type length

*array = array[0];

* (ARRAY+K) =array[k];

* (array-4) = 8;

ARRAY[-4] = 8;//there is no bond check in C, so it'll put 8 at the corresponding address. This isn't 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 the heap which store "ADM" (with string end sign).

--strcpy (Paim, "4021");
"4021" is copied to 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);} 

Programming Paradigm Episode3 and 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.