Go through the following code sinippet
char a[20];
a="Hello Orcale Test";
will this compile?

Answers were Sorted based on User's Feedback



Go through the following code sinippet char a[20]; a="Hello Orcale Test"; will..

Answer / jaisai

No...
Compile time error will occur says

"left operand must be l-value"

alternatively

char *a;
a="Hello Orcale Test";

will compile....

Is This Answer Correct ?    6 Yes 0 No

Go through the following code sinippet char a[20]; a="Hello Orcale Test"; will..

Answer / vikraman.j

Compile time err wil occur;
We can use *a="Hello Orcale Test" or a[20]="Hello Orcale
Test";
It will lead the prg nice.

Is This Answer Correct ?    2 Yes 0 No

Go through the following code sinippet char a[20]; a="Hello Orcale Test"; will..

Answer / 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

Go through the following code sinippet char a[20]; a="Hello Orcale Test"; will..

Answer / vignesh1988i

the above variable 'a' is a character array , so i would not been wrong if it has been initilized on the same line.....
but they have done that in the next line , there lies the mistake... THIS PROGRAM WILL GIVE AN ERROR why because we cant copy the entire string in a single travel by using '='(assignment) operator unless it's an initilization directly/.....


thank u

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Do you know the use of fflush() function?

0 Answers  


What are global variables and how do you declare them?

0 Answers  


write a c code "if you give a any decimal number then print that number in english alphabet"? ex: i/p: 552 o/p: five hundred fifty two ...

1 Answers   Philips,


write a c program to find largest of three numbers using simple if only for one time.

1 Answers  


What is pass by reference in c?

0 Answers  






difference between string and array?

6 Answers  


A array contains dissimilar element how can we count, and A array contains dissimilar element how can we store in another array with out repetition.

4 Answers  


atoi, which takes a string and converts it to an integer. write a program that reads lines(using getline), converts each line to an integer using atoi and computes the average of all the numbers read. also compute the standard deviation

0 Answers  


the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset

0 Answers  


Explain the difference between exit() and _exit() function?

0 Answers  


Write program to remove duplicate in an array?

0 Answers  


m=++i&&++j(||)k++ printf("%d"i,j,k,m)

1 Answers   ABC,


Categories