Home > php教程 > PHP开发 > body text

The difference between strings and arrays in C language

高洛峰
Release: 2016-12-12 17:25:28
Original
2024 people have browsed it

The elements of an array can be of any type, while a string is a special type of array that uses a well-known rule for determining its length.

There are two types of languages, those that simply treat strings as an array of characters, and those that treat strings as a special type. C belongs to the former category, but there is one addition, that is, the C string is terminated with a NUL character. The value of an array is the same as the address of the first element in the array (or a pointer to that element), so generally a C string and a character pointer are equivalent.

The length of an array can be arbitrary. When an array name is used as an argument to a function, the function has no way of knowing the size of the array from the array name itself, so some kind of rule must be introduced. For strings, this rule is that the last character of the string is the ASCII character NUL('Note: Some people call this phenomenon "C humor". It is precisely because of this humor that most C programmers are troubled by the programs they write all day long, and rarely take a break from their busy schedule.

Related labels:
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template