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

Is linux written in c?

0 Answers  


What is difference between structure and union in c programming?

0 Answers  


5. What kind of sorting is this: SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort

2 Answers   Accenture,


How will you allocate memory to a double pointer ?

2 Answers  


What is the purpose of sprintf() function?

0 Answers  






What is the difference between array and pointer in c?

0 Answers  


Write a programme to find even numbers without using any conditional statement?

3 Answers   ADD Software, Infosys,


Explain how can I write functions that take a variable number of arguments?

0 Answers  


LOGIC OF Bodmas?

1 Answers  


What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) main(); }

4 Answers   Infosys, TCS,


write a program to search for an element in a given array. If the array was found then display its position otherwise display appropriate message in c language

18 Answers   IT Park, TCS,


What is the function of volatile in c language?

0 Answers  


Categories