character pointers, character arrays, string differences between double quotes and contact

Source: Internet
Author: User

Author: Chen Zongquan

Let's start with a string of double quotes, like "Chenzongquan", which consists of a series of characters we see inside and a trailing ' plus ' character, stored in the memory's read-only store. Read-only storage is preserved and visible throughout the run of the program, and the data in principle remains unchanged. So a double quote string, as long as you know its specific address, can be used again in any function of the program.

When it comes to read-only, it is cited that there is no memory access protection in the 16-bit system, so the data in the read-only store can actually be changed while the program is running, but there is memory access protection in the 32-bit system, which causes an exception when the program runs to change the data in the read-only store. The meaning of Const is also "read-only", but this read only works on the compiler, and the compiler can, to some extent, avoid modifying the data by syntax checking. Once the program is running, the const does not work.

Say again the character array. A character array is a set of spaces to hold characters. Its space is readable and writable. If it is a global variable, it will persist throughout the run of the program and, if it is a local variable, only within its scope. It is intended to put a set of characters, not necessarily related to the string, but for historical reasons, it is entangled with the string.

    Talk about history. In the C language, the basic data types do not have string types (in fact, there are also no strings in the basic data type of c++/java/c#, except that they all provide a encapsulated type to handle the string), but the string is often processed in the program, so a character array is used to hold the string. A character array requires a fixed length as an array, but the string length is not necessarily, so the use of a measure is to use ' s ' in the character array to represent the end of the string, in this character array, but the character after ' s ' is not the string. To make it easier to use a string, just specify the address of the first character of the string, find the first character by it, and then look backward to find the second, third character, and so on, until you find ' s ', and you've traveled through the entire string, Therefore, the C syntax specifies that a string is referenced by the address of the first character. In an array, the array name represents the address of the first element in the array, and in the character array, the array name represents the address of the first character in the array, so it is often used to refer to the string in the character array name.

A character array is just a set of characters that can be used as a string only if the character array is the ' \ s ' character, so the character array is not necessarily a string.

 

The character pointer is a space used to save the address, a character in an in-memory address, without saving characters. It has nothing to do with the string, because it does not even have a single character at all, just the address of a character somewhere else. But also because of the historical reasons mentioned above, C language through a character address to refer to the string, so often through the character pointer to the memory of the other place to refer to the string. There is no point in having a character pointer stand-alone, since it is the address of a character that holds another place, it must really have a character in another place, and after saving its address to the character pointer, the character pointer begins to make sense. You can use this character pointer to refer to another character or to a string that is headed by that character.

character pointers, character arrays, string differences between double quotes and contact

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.