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
Patricia ArquetteOriginal
2024-12-15 15:04:29768browse

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!

Statement:
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