String in c language

String definition -:  A string is a sequence of characters that is treated as a single data item.  Any group of character (except double quote sign) defined between double quotation marks is a string constant as like

” Vikarm is always right ”

if we want to include a double quote in the string to be printed then we may use it with a black slash as like

printf(“\n” Vikarm is always right”\ “)

output is

” Vikarm is always right ”

while if we write this

printf(” Vikarm is always right “)

then output is

” Vikarm is always right ”

character string are often used to build meaningful and readable programs. some operation are used these are

  • reading and writing statement
  • combing string togather
  • copying one string to another
  • comparing string for equality
  • extracting of portion of a string

Declaring and initializing of string variable-: C does not support string as a data types. It allows us to represent character arrays. therefore in C  a string variable is any valid c variable name and is always declared as array of characters. as like

char string_name[size];

the size of depend of number of character in the string name

char city [10];

char name[15];

when the compiler assign a character string to a character array it automatically supplies a null character (‘\0’) at the end of string. Therefore the size should be equal to the maximum number of character in the string plus one.

 

Leave a Comment