Go through the following code sinippet
char a[20];
a="Hello Orcale Test";
will this compile?

Answer Posted / pradeep

Dear frd,

char a[20];
a="Hello Orcale Test";

Here you are trying to "assign" constant char string to
address variable , as you are aware that name of an array
points to the first address of the array element. So here
you wil get an error message saying L value is required.

and also
char *a;
*a="hello" ; also will give an error as you are trying to
assign constant characters to char type variable.
Type mismatch will occur.

so I suggest you to use the strcpy method to copy a
constant character string to char*

so soln is
char a[20];
strcpy(a,"hello world");

or char *a;
a="hello";

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is stack a keyword in c?

632


How is a macro different from a function?

652


What is the use of linkage in c language?

611


What is || operator and how does it function in a program?

622


Is printf a keyword?

755






What are the 5 types of organizational structures?

546


What are c header files?

573


Can we access array using pointer in c language?

640


How can you find the day of the week given the date?

611


Explain union. What are its advantages?

613


Why does notstrcat(string, "!");Work?

639


What is ambagious result in C? explain with an example.

2051


Explain Basic concepts of C language?

640


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

630


Why calloc is better than malloc?

570