Whats wrong with the following function
char *string()
{
char *text[20];
strcpy(text,"Hello world");
return text;
}
Answers were Sorted based on User's Feedback
Answer / 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 |
as for as i know , there is only one error..... you have
declared text as array of pointers and not as character data
array..... so this text can only accept addresses.... :)
char *text[20] means you are going to store 20 addresses in
this array..... When you store addresses using arrays , the
that is called array of pointers....
if u declare : char text[20] , this will work correctly..
thank u
| Is This Answer Correct ? | 13 Yes | 2 No |
Answer / qint
1. returning address of a local variable.
2. wrong parameter passed to strcpy()
| Is This Answer Correct ? | 4 Yes | 5 No |
3. When do you say that a digraph is acyclic A)if and only if its first search does not have back arcs B)a digraph is acyclic if and only if its first search does not have back vertices C)if and only if its first search does not have same dfnumber D)None of these
what is the output of printf("%d",(scanf("%d",10));
main is a predefined or user define function if user defined why? if predefined whay?
What do mean by network ?
Explain how can I prevent another program from modifying part of a file that I am modifying?
What is difference between %d and %i in c?
What is the meaning of this decleration? unsigned char (*pArray[10][10]); please reply.
Difference between macros and inline functions? Can a function be forced as inline?
0 Answers HAL, Honeywell, Zomato,
whats the use of header file in c?
24.what is a void pointer? 25.why arithmetic operation can’t be performed on a void pointer? 26.differentiate between const char *a; char *const a; and char const *a; 27.compare array with pointer? 28.what is a NULL pointer? 29.what does ‘segmentation violation’ mean? 30.what does ‘Bus Error’ mean? 31.Define function pointers? 32.How do you initialize function pointers? Give an example? 33.where can function pointers be used?
Write a program to reverse a given number in c language?
What is your favorite subject?
1 Answers Ericsson, Invendis, Tech Mahindra,