Difference between const void * a and void * const a, and constvoid

Source: Internet
Author: User

Difference between const void * a and void * const a, and constvoid
Const void *

This defines a pointer a. a can point to any type of value, but it must point to a constant.

In this case, we cannot modify the object to which the pointer is directed, but we can point the pointer to another object.

For example:

Const void * a; * a = 0x123; // It cannot be compiled because * a contains a const value. The const value cannot be changed.

Const int m = 1; const int n = 2;

A = & m; a = & n; // compilation is successful.

 

Void * const

This defines a const pointer a. a can point to any type of value, but a is a constant pointer to an object.

We cannot modify the address stored in the pointer, but we can modify the object pointed to by the pointer.

For example:

Void * const a; this definition: * a = 0x123; no problem,

However, a = (void *) & B; is not acceptable because a is a const variable.

For example:

Int m = 1; nt n = 2;

A = & m; a = & n; // compilation fails.

 

In this case, const modifies * a in const void *. In void * const a, const modifies.

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.