Void of C language learning notes

Source: Internet
Author: User

Void of C language learning notes

? 1. void literally means "no type", void * means "no type Pointer", and void * can point to any type of data.

? 2. Usage 1: Data Type Encapsulation

Int InitHardEnv (void ** handle );

Typical function prototypes for memory operation functions such as memcpy and memset are

Void * memcpy (void * dest, const void * src, size_t len );

Void * memset (void * buffer, int c, size_t num );

? 3. Usage 2: Modify the return value and parameters of the void function, which only indicates none.

If the function does not return a value, declare it as void.

If the function has no parameters, you should declare the parameter as void.

Int function (void)

{Return 1 ;}

? 4. Significance of the void pointer

C language requires that only pointers of the same type can be assigned values to each other

Void * the pointer is used as the left value to receive any type of pointer.

Void * forced type conversion is required when the pointer is assigned to another pointer as the right value

Int * p1 = NULL;

Char * p2 = (char *) malloc (sizoeof (char) * 20 );

? 5. The void type variable does not exist.

The C language does not define the alias for how much memory the void is.

Related Article

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.