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 string length in c?

0 Answers  


What are the different types of constants?

0 Answers  


wt is d full form of c

6 Answers   TCS, Wipro,


What is typedef example?

0 Answers  


Give the Output : * * * * * * * * * *

2 Answers  






What is main return c?

0 Answers  


main() { printf("hello"); fork(); }

0 Answers   Wilco,


which type of aspect you want from the student.

0 Answers   IBM, TCS,


What is difference between %d and %i in c?

0 Answers  


What is bss in c?

0 Answers  


Given below are three different ways to print the character for ASCII code 88. Which is the correct way1) char c = 88; cout << c << " ";2) cout.put(88);3) cout << char(88) << " "; a) 1 b) 2 c) 3 d) constant

0 Answers  


What is chain pointer in c?

0 Answers  


Categories