What is the difference between the const in C + + and C language?

Source: Internet
Author: User

It is well known that the C language can be modified by using const;

C language can be modified by  
the pointer int  main ()  
{  
//So to speak in C language A is a read-only constant. According to the theory we are not easy to modify//  
const int a=10;
printf ("%x", &a); The constant A in the//c language  can be addressed.  
int *p=null;  
p= (int *) &a;     But can modify *p=11 by address  
;  
printf ("After%d Modified", a);  
}

This is a can be modified;

But look at the following C + + inside the

and in C + +, it can be defined like this.

The C + + compiler puts him in the symbol table during compilation  
//A is a true constant according to the above.  
int const A = ten;  
      
int  const B = one;  
The length is given down at compile time  
//  array [10+11]//inside must be a constant; C + + compiled with fixed length  
//So this is OK, but in C language it can't be  
int Array[a + b] = {0};

If the brother has an unreasonable explanation, you can leave a comment, because the younger brother is also new;

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.