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
Why isn't it being handled properly?
What is the difference between malloc() and calloc() function in c language?
Is a pointer a kind of array?
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above
Why do we use stdio h and conio h?
What does the error message "DGROUP exceeds 64K" mean?
What’s a signal? Explain what do I use signals for?
Can i use “int” data type to store the value 32768? Why?
The file stdio.h, what does it contain?
How can I do graphics in c?
What is enumerated data type in c?
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
How will you divide two numbers in a MACRO?
What are operators in c?
Explain data types & how many data types supported by c?