Edgar Oliveira
Edgar Oliveira

Reputation: 323

character string or string constant

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?

Upvotes: 0

Views: 2892

Answers (3)

Rudra
Rudra

Reputation: 1688

  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

Upvotes: 2

August Karlstrom
August Karlstrom

Reputation: 11377

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*/

Upvotes: 2

Dhruv Khatri
Dhruv Khatri

Reputation: 813

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.

Upvotes: 0

Related Questions