c语言程序设计字符串
今天我们学习C语言程序设计第7章——字符串的内容。今天的主要内容有三部分,分别是字符串字面量,字符串的存储,字符指针。Today we are learning about C Programming Chapter 7 - Strings. The three main parts of today"s topic are string literals, string storage, and character pointers.
No. 1 字符串字面量
字符串字面量,有时也称为字符串常量,它是由一对双引号括起来的一个字符序列。如"hello","123"等都是字符串。无论双引号内是否包含字符,包含多少个字符,都代表一个字符串字面量。字符串实际就是由若干有效字符构成且以字符‘ ’作为结束的一个字符序列。1. A string literal, sometimes called a string constant, is a sequence of characters enclosed by a pair of double inverted commas. For example, "hello", "123", etc. are all strings. Whether or not the double quotes contain characters, and how many characters they contain, they represent a string literal. A string is actually a sequence of valid characters that ends with the character " ".
No. 2字符串的存储
2.一个字符串可以存在于字符数组中,但一个字符型数组中存储的并非一定是一个字符串,这要看它的最后一个元素是否为‘ ’,字符数组是由字符构成的数组,仅当其最后一个元素是‘ ’时才表示字符串。字符串结束标识‘ ’也占一个字节的内存,但它不计入字符串的实际长度,只计入数组的长度。2. A string can exist in an array of characters, but what is stored in a character array is not necessarily a string, it depends on whether its last element is " ", a character array is an array of characters, only when its last element is " " indicates a string. The end-of-string identifier " " also takes up a byte of memory, but it does not count towards the actual length of the string, only towards the length of the array.
No. 3字符指针
3.字符指针是指向字符型数据的指针变量。只要将字符串的首地址赋值给字符指针,即可让字符指针指向一个字符串。字符串字面量本身代表的就是存放它的常量存储区的首地址,是一个地址常量。3. A character pointer is a pointer variable that points to character type data. A character pointer can be made to point to a string simply by assigning the first address of the string to the character pointer. The string literal itself represents the first address of the constant store in which it is stored, and is an address constant.
参考资料:文字:百度;图片:微博;翻译:百度翻译
本文由LearningYard新学苑原创,部分图片文字来自网络,如有侵权请联系。