PDA

View Full Version : In C++ is SPACE is also a charactor??



sana.pari
04-24-2011, 04:53 PM
Dear Sir, i tried to display my name through arrays in previous lectures and i successfully did that. but no i tried to display my complete name through arrays like TARIQ MEHMOOD. in this case only tariq is printed on the screen where as mehmood is skipped away. what is the solution to display my complete name including space?????

Support
04-24-2011, 04:55 PM
Dear student!
You should check initialization of array. String array can be initialised at the time of declaration just as other variables are initialised. For example:
char s1[] = "example";
char s2[20] = "another example" would store the two strings as follows:

s1 |e|x|a|m|p|l|e|\0|
s2 |a|n|o|t|h|e|r| |e|x|a|m|p|l|e|\0|?|?|?|?|