The difference between C + + char a[] and char *a, changing the cause of a char *a burst memory error

Source: Internet
Author: User

For some functions that need to pass in a parameter of char * temp pointer class;

We define a char a[10] or char *a to pass in.

But

If the function is to change the value of the parameter you passed in, the incoming Char *a will burst the memory error, and Char a[10] will not.

For example: strtok in the following. strcpy, strcat If the first argument is passed to the char *a pointer type, it will cause a burst memory error.

I did not use char in my example *

Reason:

Pointer type * It is not allocated address space, defined is a pointer constant, constant to change its value, naturally wrong.

and a[] is in the address space.

The difference between C + + char a[] and char *a, changing the cause of a char *a burst memory error

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.