Why is the code below functioning. According to me it MUST
NOT.



Why is the code below functioning. According to me it MUST NOT...

Answer / 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

More C Interview Questions

Write a C++ program to give the number of days in each month according to what the user entered. example: the user enters June the program must count number of days from January up to June

0 Answers  


How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

2 Answers   CMC, Wipro,


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

0 Answers   TCS,


A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream

0 Answers  


Is it possible to run using programming C for Java Application?

2 Answers   NIC,






Define macros.

0 Answers   Tech Mahindra,


what is answer for perfect number????????????????

1 Answers  


Write a routine that prints out a 2-D array in spiral order!

1 Answers   Lucent,


write a program to print data of 5 five students with structures?

0 Answers  


What are the advantages of using new operator as compared to the function malloc ()?

0 Answers   NIIT,


HOW TO HANDLE EXCEPTIONS IN C

8 Answers  


Program to trim a given character from a string.

5 Answers   NetApp,


Categories