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

WHAT IS LOW LEVEL LANGUAGE?

2 Answers  


Why c language?

0 Answers  


1.)how to find d most repeated word in a string? string ="how do you do"?? output should be do

1 Answers   AAS, Nagarro, Vuram,


. Explain the differences between fork() and exec() in C

2 Answers  


What is difference between Structure and Unions?

0 Answers   TISL,


How the C program can be compiled?

11 Answers   HP,


12344321 123 321 12 21 1 1 how i print this program??

5 Answers   DSR Management, Winit,


what will be the output of this program........ main() { int a=2,b=4,c=6; printf("%d"); } why it gives the value of third variable.

6 Answers   HCL,


Please write me a program to print the first 50 prime numbers (NOT between the range 1 -50)

5 Answers   IBM, KJH,


write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

0 Answers   IBM,


swap 2 numbers without using third variable?

0 Answers   IBS,


main() { char as[] = "\\0\0"; int i = 0; do{ switch( as[i++]) {case '\\' : printf("A"); break; case 0 : printf("B"); break; default : printf("C"); break; }} while(i<3); }

4 Answers   Vector, Vector India,


Categories