简体   繁体   English

C中字符串常量和字符串文字有什么区别?

[英]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.

相关问题 C - 初始化程序与字符串文字不一致 - C - initializer not constant with string literal 这4项之间有什么区别:字符,数组,字符串,文字。 在C? - what's the difference between these 4 item:character,array,string,literal. in C? 在C中创建字符串的方法有什么区别? - What is the difference between the ways to create a string in C? 数组和指向字符串文字的指针之间的差异 - Difference between array and pointer to string literal 字符串字面量和 const char[] 或 char[] 之间的区别 - Difference between string literal and const char[], or char[] C字符串和C ++字符串有什么区别? - What is the difference between the C string and C++ string? 首先将字符串指针分配给已分配的内存,然后直接分配给字符串文字,这有什么区别? - What is the difference between assigning a string pointer first to allocated memory and directly to a string literal? 字符串文字和 const 字符串文字有什么区别 - What are the differences between string literal and const string literal 在C中反转字符串的函数-如果字符串文字是什么? - Function to reverse a string in C - What if is a string literal? 字符串和用户在C中输入的字符串之间的区别是什么 - What's the difference between a string and a user entered string in C
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM