[英]What is the difference between a String Constant and String Literal in C?
What's the difference between a String Constant and String Literal in plain C? 普通C中字符串常量和字符串文字之间有什么区别?
This question is similar to another: What's the difference between a string constant and a string literal? 这个问题与另一个问题类似: 字符串常量和字符串文字有什么区别? ...except that one was regarding Objective-C (using NSString) and not C.
...除了一个是关于Objective-C(使用NSString)而不是C.
In the C99 Draft from 2007 the term sting literal is used. 在2007年的C99草案中,使用了sting literal一词。 The term string constant does not appear in the draft at all.
术语字符串常量根本不会出现在草稿中。
I find string literal to be a good term choice when talking about "foo" (just as 42 is a literal number, "foo" is a literal string). 在谈论“foo”时,我发现字符串文字是一个很好的术语选择(正如42是文字数字,“foo”是文字字符串)。
They are one and the same. 他们是一样的。 Merely a preference in which word you use to describe the string.
仅仅是您使用哪个词来描述字符串的首选项。
The spelling of the second word used to describe the same idea? 第二个单词的拼写用来描述同一个想法?
I would regard them as the same thing - alternative terms for the same construct. 我认为它们是同一个东西 - 同一构造的替代术语。
const char * strConst;
strConst = "Hello World";
In this example 在这个例子中
strConst
is a string constant. strConst
是一个字符串常量。 "Hello World"
is a string literal, and is typically stored in the read only area of the program. "Hello World"
是字符串文字,通常存储在程序的只读区域中。 文字和常量意味着相同,这是在源代码中表示固定值的符号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.