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 macro, and explain how do you use it?
Define Spanning-Tree Protocol (STP)
Explain high-order and low-order bytes.
What is the difference between void main and main in c?
How do you generate random numbers in C?
Explain goto?
How does pointer work in c?
Explain function?
can any one provide me the notes of data structure for ignou cs-62 paper
What is a constant and types of constants in c?
I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.
What is binary tree in c?
What are keywords in c with examples?
What are the functions to open and close the file in c language?
Hello. How to write a C program to check and display president party like if i type in the console "biden" and hit enter the output shoud be : "biden is democrat" and if i type "trump" and hit enter the output shoud be: "trump is republican"