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
Is c procedural or object oriented?
What do the functions atoi(), itoa() and gcvt() do?
Under what circumstances does a name clash occur?
What is a string?
Explain how do you view the path?
how we can make 3d venturing graphics on outer interface
Why is C language being considered a middle level language?
What are pointers? What are stacks and queues?
Explain what is a const pointer?
What is a pointer on a pointer in c programming language?
When do we get logical errors?
What do you mean by a local block?
write a c program in such a way that if we enter the today date the output should be next day's date.
Explain how do you generate random numbers in c?
What are all different types of pointers in c?