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 main is used in c?
I came across some code that puts a (void) cast before each call to printf. Why?
I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.
What are logical errors and how does it differ from syntax errors?
How many levels of indirection in pointers can you have in a single declaration?
What is the difference between array and pointer?
what is the diffrenet bettwen HTTP and internet protocol
Write a program to check prime number in c programming?
Whats s or c mean?
a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none
Tell me is null always defined as 0(zero)?
What is the difference between formatted&unformatted i/o functions?
Explain what does it mean when a pointer is used in an if statement?
What is string constants?
Why is c not oop?