0
votes

I am reading the book "The C Programming Language" by Brian W. Kernighan and Dennis M. Ritchie.

They talk about "character string" and "string constant". What is the difference between these concepts?

3

3 Answers

2
votes

A string constant is a sequence of characters enclosed in double quotes. A character string is a sequence of characters ending with '\0' stored in a character array or pointed to by a character pointer.

Example:

#include <string.h>

char s[4];

strcpy(s, "foo"); /*"foo" is a string constant and s contains a character string*/
2
votes
  1. A character constant consists of a single characters enclosed within single inverted commas.
  2. A string constant may consist of any combination of digits, letters, escaped sequences and spaces, a sequence of characters enclosed in double quotes.

Check out this link enter image description here

0
votes

string constant: Text enclosed in double quote characters (such as "example" ) is a string constant.

Character String: Strings are actually one-dimensional array of characters terminated by a null character '\0'. So basically the difference is character String is the object and string constant is the way to representation.