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
What is a constant?
What is the difference between functions getch() and getche()?
What are the advantages of using linked list for tree construction?
What is masking?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......
What is file in c language?
explain what is a newline escape sequence?
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
What is void main ()?
what do the 'c' and 'v' in argc and argv stand for?
What are data structures in c and how to use them?
State two uses of pointers in C?
What is an array in c?