Why is the code below functioning. According to me it MUST
NOT.



Why is the code below functioning. According to me it MUST NOT...

Answer / h0rryp0tter

Please have a look at the code below :

char str[1];
int i = 0;
void revstr(void);

int main(void)
{

revstr();
printf("%s\n",str);

return 0;
}

void revstr(void)
{
char c = getchar();

if (c!= EOF) {
revstr();
str[i++] = c;
}
str[i] = '\0';
}

Written using Bloodshed Dev C++.

I am trying to access and write on an char array which has
been defined with only one element in it. The above code
must give me Errors of some kind. But on the contrary, it
works.

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

Write down the program to sort the array.

4 Answers   Impiger,


What is return type in c?

0 Answers  


What does char * * argv mean in c?

0 Answers  


How many types of arrays are there in c?

0 Answers  


Explain what is page thrashing?

0 Answers  






Explain how do you declare an array that will hold more than 64kb of data?

0 Answers  


What's the right way to use errno?

0 Answers  


What is const keyword in c?

0 Answers  


Do you know pointer in c?

0 Answers  


There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys.

0 Answers  


how to swap 2 numbers in a single statement?

3 Answers  


Which is best linux os?

0 Answers  


Categories