How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
RE: How can a character and a string with only one c...
A character means a single alphabet. But string means a group of characters enclosed within within double quotes having a null character at the end. In case if you are in a need to use a character you can use a single character rather than a string. What is the purpose of using a single character in a string?
RE: How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
RE: How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
use c for printing a character and s for printing the string. else it'll crash
RE: How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
There are various things to be observed for this 1. First of all while at the time of storing
single character is stored as char abc 's'; where as string having single character can be stored as char pqr[] "s";
2. single character takes one byte for storage String (even single character is stored) takes two bytes one for one character and second for null character.
This can be verified by following C statement:
printf(" d d" sizeof(abc) sizeof(pqr)); which gives output as 1 and 2 respectively. (assuming turbo C compiler and 1 byte for char)
RE: How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
A character is a interger in the range -127 to 127. You can set a char value using interger. for example the character 'a': char cc 141; The string "a" is not a integer a string defines a GROUP of characters and for a single character string it happens to be a group with only one member. But the nature is still a group not a member.