0
What's happening here?
Please explain the output of my code below. Thank you :))) https://code.sololearn.com/c7b3G9YDAfDV/?ref=app
5 Respostas
+ 7
1) here's an ascii table which you can look
https://en.cppreference.com/w/cpp/language/ascii
as you can see null termination character has 0 as ascii code and space is 32nd..
2) "\0" is just evaluated as a single character not as two different things.. as its escape sequence .. all escape sequence (ascii ones) start with \ .. look at this : https://www.google.com/amp/s/www.geeksforgeeks.org/escape-sequences-c/amp/
+ 6
Leme explain line by line
char str[30]="HELLO WORLD 0 ZERO \0 HI";
here we have a char array which is actually terminated after ZERO .. by null termination escape sequence ..
and '\0' is same ad having 0 at that index..
int index=0;
we start at index 0
while (str[index]!=0) // run the loop untill a 0 is encountered ( '\0' is also 0)
{
if(isupper(str[index]))
{
printf("%c",str[index]); // print the character only if its upper case
}
++index; // keep on going
}
+ 1
Martin Taylor ooh yes, I searched the internet for ASCII value 0 and it said NULL. I mistakenly took it for space, now I thought space is something, NULL is nothing. Am I right??
0
Prashanth Kumar I have some clarifications to be made here.
1)Why isn't the loop terminated when encountering a space(because the ASCII value of a space is 0 right?).
2) '\' and '0' are 2 unique characters right? How is '\0' a single character??