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
Why can’t we compare structures?
What does return 1 means in c?
Explain the difference between exit() and _exit() function?
What are the advantages of c preprocessor?
What is call by value in c?
Explain the difference between null pointer and void pointer.
What is LINKED LIST? How can you access the last element in a linked list?
What is getche() function?
How can you tell whether a program was compiled using c versus c++?
How many types of functions are there in c?
How #define works?
What is volatile variable in c with example?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What is a pointer value and address in c?
pierrot's divisor program using c or c++ code