Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

shorting algorithmS

2252


Why does this code crash?

1085


What is data types?

1078


How do you search data in a data file using random access method?

1299


Is null always defined as 0(zero)?

1099


Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.

2231


What is the best way to store flag values in a program?

1070


What are bitwise shift operators in c programming?

1075


What does c mean before a date?

1174


If null and 0 are equivalent as null pointer constants, which should I use?

1210


What is wrong with this declaration?

1105


code for quick sort?

2027


What is #include stdio h and #include conio h?

1101


What does the c in ctime mean?

1087


How many levels of indirection in pointers can you have in a single declaration?

1085