Why is the code below functioning. According to me it MUST
NOT.
Answer Posted / 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 View All Answers
What is a buffer in c?
What is else if ladder?
Wt are the Buses in C Language
What is function prototype in c with example?
In c language can we compile a program without main() function?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
how many errors in c explain deply
Can we declare a function inside a function in c?
Difference between linking and loading?
Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.
Write a factorial program using C.
What are operators in c?
What is indirection? How many levels of pointers can you have?
What is the significance of an algorithm to C programming?
What is c system32 taskhostw exe?