C Strings:
A sequence of characters, internally stored in the form of an array of characters is called as string.
Declaration of String:
In C, a string can be specified in two ways:
Character Array:
A string declared as an array, where each character represents an element of that array, is called as Character Array.
Syntax:
char array_Name[] = {char1,char2,char3………};
String Literal:
A string declared as an array, where the whole string represents a complete array, is called as String Literal.
Syntax:
char array_Name[] = “stringValue”
Example :
#include<stdio.h> #include <string.h> void main() { char chr[]={'H', 'E', 'L', 'L', 'O', ' ', 'C', '\0'}; char str[]="HELLO C"; printf("String in form of character array: %s\n", chr); printf("String in form of string literal: %s\n", str); } |
Output
String in form of character array: HELLO C String in form of string literal: HELLO C |