Go through the following code sinippet
char a[20];
a="Hello Orcale Test";
will this compile?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
compute the nth mumber in the fibonacci sequence?
10 Answers Canon, HPL, Satyam, TCS,
Write a program that an operator and two operands read from input operand operator on the implementation and results display.
What is a null string in c?
get any number as input except 1 and the output will be 1.without using operators,expressions,array,structure.don't print 1 in printf statement
Please write me a program to print the first 50 prime numbers (NOT between the range 1 -50)
Would you rather wait for the results of a quicksort, a linear search, or a bubble sort on a 200000 element array? 1) Quicksort 2) Linear Search 3) Bubble Sort
main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] =(char) (k%16 > 9 ? k%16 - 10 + 'a' : '\0' ); } while(k /= 16); printf("%s\n", trans); }
Write a progarm to find the length of string using switch case?
what r callback function?
What does the function toupper() do?
What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above