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 void pointers in c?
Why is a semicolon (;) put at the end of every program statement?
A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler
How to establish connection with oracle database software from c language?
Explain about the constants which help in debugging?
What is n in c?
How can I implement a delay, or time a users response, with sub-second resolution?
Is c weakly typed?
Explain what is wrong with this program statement? Void = 10;
Explain how can I write functions that take a variable number of arguments?
Write a code to generate divisors of an integer?
Write a factorial program using C.
Explain how do you list a file’s date and time?
Write a program to reverse a given number in c language?
How do you use a 'Local Block'?