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...

Whats wrong with the following function

char *string()
{
char *text[20];
strcpy(text,"Hello world");
return text;
}

Answer Posted / avinash

In this question ,two wrong thins ----
1.this is an array of char pointer so use
strcy(text[no.],"Hello World");

2.
we are copying a string without allocating memory to pointer . This is bug code .

correct solution :----

char *string()
{
char *text[20];
text[0]=malloc(20*sizeof (char));
strcpy(text,"Hello world");
return text;
}

Is This Answer Correct ?    15 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you redirect a standard stream?

1150


What is use of #include in c?

1220


main() { printf("hello"); fork(); }

1248


Can we access array using pointer in c language?

1127


What are the 4 types of programming language?

1187


Difference between macros and inline functions? Can a function be forced as inline?

1349


What is the g value paradox?

1249


What is .obj file in c?

1129


Function calling procedures? and their differences? Why should one go for Call by Reference?

1133


What is the difference between array_name and &array_name?

1349


which is an algorithm for sorting in a growing Lexicographic order

1862


Explain what is the stack?

1157


Do you know what are bitwise shift operators in c programming?

1153


What is use of pointer?

1165


What is string function in c?

1049