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

write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?

2138


Why c is called a middle level language?

1114


What are register variables? What are the advantage of using register variables?

1191


What is the benefit of using const for declaring constants?

1049


What is time null in c?

1075


What is time complexity c?

1000


Explain what are the different data types in c?

1225


What is difference between class and structure?

1116


Is there any data type in c with variable size?

1103


What does p mean in physics?

1046


Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?

1070


Explain About fork()?

1119


Do you know null pointer?

1029


please send me the code for multiplying sparse matrix using c

2177


what are the advantages of a macro over a function?

1146