Whats wrong with the following function

char *string()
{
char *text[20];
strcpy(text,"Hello world");
return text;
}

Answer Posted / vignesh1988i

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What language is c written?

577


Explain what is a const pointer?

640


What does %c mean in c?

647


What is the difference between int main and void main in c?

591


How do you print an address?

745






State the difference between realloc and free.

635


What is zero based addressing?

713


How do you define CONSTANT in C?

651


Write a program on swapping (100, 50)

636


What is the use of define in c?

594


How can you call a function, given its name as a string?

712


Write a c program to demonstrate character and string constants?

1683


Explain why c is faster than c++?

574


Can we access array using pointer in c language?

640


Is there sort function in c?

576