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

Define Array of pointers.

635


What are keywords in c with examples?

604


What is meant by preprocessor in c?

536


Explain bitwise shift operators?

632


Is null always defined as 0(zero)?

616






Place the #include statement must be written in the program?

573


Explain how can I convert a number to a string?

650


Explain what does the function toupper() do?

636


Why does the call char scanf work?

620


Explain how can a program be made to print the name of a source file where an error occurs?

691


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.

1727


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

1253


Difference between strcpy() and memcpy() function?

680


Is exit(status) truly equivalent to returning the same status from main?

587


Explain what is meant by high-order and low-order bytes?

635