C NULL CharacterPritesh
NULL Character : Terminating Character in String
Why do we need Terminating Character ?
- C Programming does not provide inbuilt ‘String‘ data type. [See Available Data Types in C]
- String is one of the most important and necessary Data Structure in C Programming
- We can say String as Variable length Structure stored in Fixed Length Structure
- Array Size is not the Actual Length of the String , So to recognize the End of the String we use NULL character
Pictorial Understanding :
In the above picture we can see –
- Before Initializing String it Contain Garbage Characters.
- Length of String [i.e Declared character array] is 7 so it Contain 7 Garbage Characters.
- When we attempt to store “CAT” in the string of Character length 7 then String Would be “CAT@’af“
|Location||Value Before Initialization||Value After Initialization|
Since valid String is “CAT” whenever we are trying to access the array using character array variable then valid string before NULL character will be considered as Valid.
Packing Up : Summary
|Without NULL character string stored will be||CAT'@af|
|ASCII Value of NULL Character||0|