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

Why can’t we compare structures?

1283


What does return 1 means in c?

1076


Explain the difference between exit() and _exit() function?

1175


What are the advantages of c preprocessor?

1268


What is call by value in c?

1010


Explain the difference between null pointer and void pointer.

1096


What is LINKED LIST? How can you access the last element in a linked list?

1075


What is getche() function?

1053


How can you tell whether a program was compiled using c versus c++?

1111


How many types of functions are there in c?

1150


How #define works?

1115


What is volatile variable in c with example?

1050


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

1043


What is a pointer value and address in c?

1135


pierrot's divisor program using c or c++ code

2246