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 |
What is the exact difference between '\0' and ""
Give the logic for this #include<stdio.h> #include<conio.h> void main() { clrscr(); int a=10,b; b=++a + ++a; printf("%d", b); getch(); } Output: 24......How?
how can be easily placed in TCS.
How do you define structure?
difference between loading and linking
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
What oops means?
1. Write a C program to count the number of occurrence of a specific word in the given strings. (for e.g. Find how many times the word “live” comes in the sentence “Dream as if you’ll live forever, live as if you’ll die today ”)
a.One Cannot Take the address of a Bit Field b.bit fields cannot be arrayed c.Bit-Fields are machine Dependant d.Bit-fields cannot be declared as static Which of the Following Statements are true w.r.t Bit-Fields A)a,b&c B)Only a & b C)Only c D)All
3 Answers Accenture, Digg.com,
Why is c so important?
Dear Sir, we are required the bubble sorting programs Regs Prem
what is the structure?