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

Difference between macros and inline functions? Can a function be forced as inline?

0 Answers   HAL, Honeywell, Zomato,


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

0 Answers  


What is volatile c?

0 Answers  


What is the size of enum in bytes?

0 Answers  


Write a C program in Fibonacci series.

0 Answers   iNautix,






What is a pointer on a pointer in c programming language?

0 Answers  


What is the difference between procedural and declarative language?

0 Answers  


String concatenation

2 Answers  


what is diognisis?

1 Answers  


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

0 Answers   HP,


what is the meaning of 'c' language

3 Answers  


What is volatile keyword in c?

0 Answers  


Categories