Home > Backend Development > C++ > What's the Difference Between `char a[] = 'string';` and `char *p = 'string';`?

What's the Difference Between `char a[] = 'string';` and `char *p = 'string';`?

Patricia Arquette
Release: 2024-12-15 15:04:29
Original
760 people have browsed it

What's the Difference Between `char a[] =

Differences between "char a[] = ?string?;" and "char *p = ?string?;"

The interviewer's question involves a typo, as the "?" operator is not semantically valid. Assuming the typographical error, we can interpret the intended question:

What is the difference between "char a[] = "string";" and "char *p = "string";"?

Arrays vs. Pointers

The primary difference between these declarations lies in the data structure they create:

  • Array (char a[] = "string";"): Initializes a character array that stores the string literal "string". It can hold multiple characters, including the null terminator ('

The above is the detailed content of What's the Difference Between `char a[] = 'string';` and `char *p = 'string';`?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template