What is the difference between a String Constant and String Literal in C?
-
29-09-2019 - |
Question
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.
Solution
They are one and the same. Merely a preference in which word you use to describe the string.
OTHER TIPS
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).
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.
Literal and constant mean the same which is notation for representing a fixed value in source code.