"
This is a discussion on Doubt regarding " " within the
C Programming forums, part of the General Programming Boards category; For the below code why it is getting a white space when trying to print c1 and nothing is printed ...
-
Doubt regarding "\0"
For the below code why it is getting a white space when trying to print c1 and nothing is printed for c2?
Code:
int main(void)
{
char c1='\0';
char c2[]="\0";
printf("h%cello\n",c1);
printf("h%sello\n",c2);
getch();
return 0;
} o/p: h ello(white space is there as it is '\0')
hello (white space is not there why???)
-
Captain Crash

Originally Posted by
karthik537
For the below code why it is getting a white space when trying to print c1 and nothing is printed for c2?
Code:
int main(void)
{
char c1='\0';
char c2[]="\0";
printf("h%cello\n",c1);
printf("h%sello\n",c2);
getch();
return 0;
} o/p: h ello(white space is there as it is '\0')
hello (white space is not there why???)
Because '\0' is a character like any other character. When you print this character you see an empty space. For a string, the situation is different -- a string that begins with '\0' is a string of zero length, and thus nothing at all is displayed.
For c1, you are literally seeing what a '\0' "looks like"
Code:
//try
//{
if (a) do { f( b); } while(1);
else do { f(!b); } while(1);
//}
-
-
Yeah, the null character's interesting; it's tripped me up in the past when I've encountered 'em in the *nix world.
That being said, it's not necessary for our latest assignment; if you're going for the homework early, go you! If not, carry on; it's interesting.
-- KB1JWQ
Popular pages Recent additions
Similar Threads
-
By shwetha_siddu in forum C Programming
Replies: 5
Last Post: 03-21-2009, 01:28 AM
-
By nacho4d in forum C Programming
Replies: 4
Last Post: 12-10-2006, 06:08 PM
-
By kalamram in forum C Programming
Replies: 1
Last Post: 04-21-2006, 05:30 AM
-
By louis_mine in forum C Programming
Replies: 3
Last Post: 08-20-2004, 11:16 AM
-
By vasanth in forum C++ Programming
Replies: 15
Last Post: 02-28-2002, 03:41 AM