Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is void pointers in c?

954


Why is a semicolon (;) put at the end of every program statement?

1027


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

1049


How to establish connection with oracle database software from c language?

2141


Explain about the constants which help in debugging?

1300


What is n in c?

969


How can I implement a delay, or time a users response, with sub-second resolution?

1032


Is c weakly typed?

962


Explain what is wrong with this program statement? Void = 10;

1190


Explain how can I write functions that take a variable number of arguments?

1027


Write a code to generate divisors of an integer?

1004


Write a factorial program using C.

1015


Explain how do you list a file’s date and time?

986


Write a program to reverse a given number in c language?

1046


How do you use a 'Local Block'?

1114