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 / vikram
b)fail1,fail2
bcoz whenever we compare strings,we use strcmp()
function,hence the condition in if() will not be true,
the control will go into else part and will print fail1,then
size of array p is 6 and sizeof(p)-2 results to 4 and hence
p[4]=='n'which again makes the condition in the if()
false,hence fail2 in else part will be printed.
thnx
Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
Where static variables are stored in c?
What is difference between stdio h and conio h?
When is a null pointer used?
What is a macro?
Define Array of pointers.
What is an expression?
What are identifiers c?
Is fortran still used today?
What does #pragma once mean?
What does & mean in scanf?
How many types of operators are there in c?
How can a string be converted to a number?
What is a char c?
Write a program to print factorial of given number using recursion?
How many types of functions are there in c?