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
write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?
Why c is called a middle level language?
What are register variables? What are the advantage of using register variables?
What is the benefit of using const for declaring constants?
What is time null in c?
What is time complexity c?
Explain what are the different data types in c?
What is difference between class and structure?
Is there any data type in c with variable size?
What does p mean in physics?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
Explain About fork()?
Do you know null pointer?
please send me the code for multiplying sparse matrix using c
what are the advantages of a macro over a function?