char* str= "Bbo"; char s1[]= "BBO" difference

Source: Internet
Author: User
The result of the expression operation is a constant value (not writable), the constant is no memory space compiled when the constant will be placed in the constant area, after the string is not modified string constants, characters are character constants (modified), see can be modified from the constant area has been placed into the register, MOV into the variable so it can be modified    char* str= "HelloWorld"; char s1[]= "BBO" the difference between int main (int argc, char* argv[]) {int a=1;    char* str= "Bbo"; *str= ' m ';    ///;c005 The reason is that the constant area of things can not be modified (can only read), and you modified so that will be reported access error //char s1[]= "Bbo"; *s1= ' P ';    This can be modified because the string is a variable in the stack (the string constant is copied inside the stack space), S1 stores the address of the first character (so can modify OK) printf ("Hello world!\n"); return 0;}

char* str= "Bbo"; char s1[]= "BBO" difference

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.