C Strings Basics
Introduction to Character Array :
In C Programming we don’t have Sting data type. In C we have to use different approach to store the string. We are creating array of character to creating string. Suppose we have to accept the name of the person then n characters are collected together and string or character array is created.
Some Points Regarding Character Array | String in C Programming :
- String in C is also called as Character Array
- String is enclosed within Double quotes
- Each Character Occupy 1 byte of Memory
- Each Character is stored in consecutive memory location
- String always Terminated with NULL Character (‘/0′)
- NULL Character is having ASCII value 0
- As String is nothing but an array , so it is Possible to Access Individual Character
'C','4','L','E','A','R','N'
"Pritesh" is a example of String
Size of "Pritesh" = Size of 'P' + = Size of 'R' + = Size of 'I' + = Size of 'T' + = Size of 'E' + = Size of 'S' + = Size of 'H'; Size of "Pritesh" = 7 BYTES
Address of 'P' = 2000 Address of 'R' = 2001 Address of 'I' = 2002 Address of 'T' = 2003 Address of 'E' = 2004 Address of 'S' = 2005 Address of 'H' = 2006
char name[10] = {'P','R','I','T','E','S','H','\0'}
ASCII Value of '\0' = 0
name[10] = "Pritesh";
It is possible to access individual character -
name[0] = 'P'; name[1] = 'r'; name[2] = 'i'; name[3] = 't'; name[4] = 'e'; name[5] = 's'; name[6] = 'h'; name[7] = '\0';