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
How old is c programming language?
Is it acceptable to declare/define a variable in a c header?
Write a program to implement queue.
What is local and global variable in c?
What are the ways to a null pointer can use in c programming language?
How can a process change an environment variable in its caller?
What is the use of pragma in embedded c?
What is c language in simple words?
What is the difference between constant pointer and constant variable?
What are the types of pointers?
What is formal argument?
Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?
What is f'n in math?
What is the collection of communication lines and routers called?
In which language linux is written?