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

How old is c programming language?

1063


Is it acceptable to declare/define a variable in a c header?

1178


Write a program to implement queue.

1169


What is local and global variable in c?

1250


What are the ways to a null pointer can use in c programming language?

1193


How can a process change an environment variable in its caller?

1235


What is the use of pragma in embedded c?

1098


What is c language in simple words?

1112


What is the difference between constant pointer and constant variable?

1278


What are the types of pointers?

1188


What is formal argument?

1189


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

1134


What is f'n in math?

1135


What is the collection of communication lines and routers called?

1180


In which language linux is written?

1288