简体   繁体   中英

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?

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.

In the C99 Draft from 2007 the term sting literal is used. 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).

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.
  • "Hello World" is a string literal, and is typically stored in the read only area of the program.

文字常量意味着相同,这是在源代码中表示固定值的符号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM