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
Why do we use main function?
hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?
What is difference between main and void main?
What is size of union in c?
What is the difference between struct and typedef struct in c?
Do character constants represent numerical values?
What is pointer and structure in c?
What is the difference between procedural and declarative language?
how to create duplicate link list using C???
Explain how can you be sure that a program follows the ansi c standard?
Why c is called a middle level language?
Explain how can a program be made to print the name of a source file where an error occurs?
What are the features of c language?
How do we declare variables in c?
What are different types of operators?