这是什么意思是"由零"?终止
我进入C / C ++和大量的术语如雨后春笋般冒出生疏了。其中之一是由一零终止的变量或指针。这是什么意思在内存空间由一个零终止?
I am getting into C/C++ and a lot of terms are popping up unfamiliar to me. One of them is a variable or pointer that is terminated by a zero. What does it mean for a space in memory to be terminated by a zero?
参加ASCII字符串你好
。在内存最简单的重新presentation是两个字节:
Take the string Hi
in ASCII. Its simplest representation in memory is two bytes:
0x48
0x69
但是,这是否一块内存结束?除非你也$ ppared通过串绕中的字节数p $,你不知道 - 内存条没有本质上的长度
But where does that piece of memory end? Unless you're also prepared to pass around the number of bytes in the string, you don't know - pieces of memory don't intrinsically have a length.
所以C有一个标准的字符串以零字节,也称为 NUL
字符结尾:
So C has a standard that strings end with a zero byte, also known as a NUL
character:
0x48
0x69
0x00
该字符串现在是明确长两个字符,因为有两个字符前 NUL
。