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
Is stack a keyword in c?
How is a macro different from a function?
What is the use of linkage in c language?
What is || operator and how does it function in a program?
Is printf a keyword?
What are the 5 types of organizational structures?
What are c header files?
Can we access array using pointer in c language?
How can you find the day of the week given the date?
Explain union. What are its advantages?
Why does notstrcat(string, "!");Work?
What is ambagious result in C? explain with an example.
Explain Basic concepts of C language?
in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above
Why calloc is better than malloc?