Headlines
Loading...
Strings

Strings


Strings are defined as an array of characters. The difference between a character array and string is terminated with a special ‘\0’ at the end, just like how you would write out numbers or letters in the text but not symbols!

Let's understand ASCII codes first. ASCII, abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices.

ASCII Codes

A - 65        a - 97        1 - 48 
B - 66        b - 98        2 - 49
C - 67        c - 99        3 - 50
D - 68        d - 100      4 - 51
.
.
.
.
Z - 90        z - 122

Declaration and Initialization of character

char temp = 'A'; //must be in single quotes and one char
printf("%c",temp); //%d me 65 aayga

Arrays of characters

char a[5];
char a[5] = {'A','B','C','D'};
char a[] = {'A','B','C','D'};

char name[10] = {'d','h','i','r','a','j'}; => Arrays of characters
|d|h|i|r|a|j|0|0|0|0|

End of the string? '\0' => null character

char name[10] = {'d','h','i','r','a','j','\0'}; => String
char name[] = "dhiraj"; => String

printf("%s", name); //sirf string me array aise print hoga
scanf("%s", name); //one word

gets(name); //multiple words like "Dhiraj Beri"

What's next?

0 Comments: