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
Define Array of pointers.
What are keywords in c with examples?
What is meant by preprocessor in c?
Explain bitwise shift operators?
Is null always defined as 0(zero)?
Place the #include statement must be written in the program?
Explain how can I convert a number to a string?
Explain what does the function toupper() do?
Why does the call char scanf work?
Explain how can a program be made to print the name of a source file where an error occurs?
4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
Difference between strcpy() and memcpy() function?
Is exit(status) truly equivalent to returning the same status from main?
Explain what is meant by high-order and low-order bytes?