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 main is used in c?

1078


I came across some code that puts a (void) cast before each call to printf. Why?

1220


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

1945


What are logical errors and how does it differ from syntax errors?

1302


How many levels of indirection in pointers can you have in a single declaration?

1088


What is the difference between array and pointer?

1019


what is the diffrenet bettwen HTTP and internet protocol

1840


Write a program to check prime number in c programming?

1093


Whats s or c mean?

1025


a sequence of bytes with one to one corrspondence to those in the external device a) sequential addressing b) address c) byte code d) none

1276


Tell me is null always defined as 0(zero)?

1089


What is the difference between formatted&unformatted i/o functions?

1056


Explain what does it mean when a pointer is used in an if statement?

1065


What is string constants?

1149


Why is c not oop?

978