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


Please Help Members By Posting Answers For Below Questions

What is a macro, and explain how do you use it?

809


Define Spanning-Tree Protocol (STP)

861


Explain high-order and low-order bytes.

860


What is the difference between void main and main in c?

851


How do you generate random numbers in C?

893


Explain goto?

901


How does pointer work in c?

811


Explain function?

853


can any one provide me the notes of data structure for ignou cs-62 paper

1895


What is a constant and types of constants in c?

835


I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

2090


What is binary tree in c?

827


What are keywords in c with examples?

812


What are the functions to open and close the file in c language?

792


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"

1805