What will be the result of the following program?
main()
{
char p[]="String";
int x=0;
if(p=="String")
{
printf("Pass 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
else
{
printf("Fail 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
}
a) Pass 1, Pass 2
b) Fail 1, Fail 2
c) Pass 1, Fail 2
d) Fail 1, Pass 2
e) syntax error during compilation
Answer Posted / shruti
syntax error during compilation..
we cannot compare strings using if(p == "string")
so will not work..
NOTE:
while comparing string otherwise also we use 'string'
(string in single quotes ' ' not " ")..
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What are the different types of constants?
What is the significance of an algorithm to C programming?
how should functions be apportioned among source files?
What the advantages of using Unions?
How is null defined in c?
What are the different types of data structures in c?
How can I split up a string into whitespace-separated fields?
What are pointers? What are stacks and queues?
What are the keywords in c?
The difference between printf and fprintf is ?
How is actual parameter different from the formal parameter?
Explain what is the difference between far and near ?
i got 75% in all semester am i eligible for your company
how can use subset in c program and give more example
Why n++ execute faster than n+1 ?