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?
What is the significance of scope resolution operator?
What is the function of this pointer?
What is the size of enum in c?
What is LINKED LIST? How can you access the last element in a linked list?
What is the -> in c?
What is #line used for?
What is pointer to pointer in c language?
can any one tel me wt is the question pattern for NIC exam
why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above
What is variable declaration and definition in c?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
Is there a way to jump out of a function or functions?
If you know then define #pragma?
Tell me what is null pointer in c?