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
An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above
Is it better to bitshift a value than to multiply by 2?
write a c program to find the sum of five entered numbers using an array named number
How do you determine a file’s attributes?
What is #define?
What is variable declaration and definition in c?
Implement bit Array in C.
Under what circumstances does a name clash occur?
Which of these functions is safer to use : fgets(), gets()? Why?
an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational
Why is sprintf unsafe?
Explain built-in function?
What are the standard predefined macros?
When do we get logical errors?
i have a written test for microland please give me test pattern