The difference between const void *a and void *const A

Source: Internet
Author: User

const void *a

This is defined as a pointer a,a can point to a value of the arbitrary type, but the value it points to must be a constant.

In this case, we cannot change the object being pointed to, but we can make the pointer point to other objects.

Like what:

The const void *a;*a=0x123;//is just a compile pass, because the *a is a const value.

The const value cannot be changed.

const int M=1; const int n=2;

a=&m; a=&n;//compilation can be passed.

void* Const A

This is defined by a const pointer a. A can point to a random type of value, but a is a constant pointer to an object.

We cannot change the address stored in the pointer. But you can change the object that the pointer points to.

Like what:

void* const A; this definition: *a=0x123; it's no problem,

But A= (void*) &b; is no good. Because A is a const variable.

Such as:

int m=1; NT n=2;

a=&m; a=&n;//compilation is unsuccessful.

Can say so. const void *a; The const modifier is *a. In void* const A, the const modifier is a.

The difference between const void *a and void *const A

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.