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...


a=0;
b=(a=0)?2:3;
a) What will be the value of b? why
b) If in 1st stmt a=0 is replaced by -1, b=?
c) If in second stmt a=0 is replaced by -1, b=?

Answers were Sorted based on User's Feedback



a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=..

Answer / syamkumarm

a)3
because it is ternery operator its work like a if.. else..
in the comdition part a=0 i.e. the result of expression is
zero so it goes to else part i.s 3

b)b=3

c)b=2

Is This Answer Correct ?    15 Yes 3 No

a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=..

Answer / ashwin kumar

3 is the answer

2nd guy says we can't use "=" it's wroung we can use it in
this condition .


expl:

1st it will check condition part , condition part will
return false as, ANY VALUE OTHER THAN ZERO TAKEN AS TRUE IN
C LANGUAGE , here we are assiging zero to 'a' which give
false.


from basic of above contion , it condition return false it
will execute or return 2nd statement, i.e 3

so out put will be 3

Is This Answer Correct ?    7 Yes 1 No

a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=..

Answer / vignesh1988i

the value is 0 so this will go to 3.. the value of b=3
a) b=3... since we are not comparing the value os a's...
this is an assignment statement.... so a itself is 0, which
is an false condition.... so it moves to 3

b) the value of b=2... since -1 ia an non zero value... the
whole term wil become true....

c) b=2... same reson as above

actually the above conditional operater statement must be
full y enclosed witin braces.... then only we should assign
to a variable....

Is This Answer Correct ?    4 Yes 2 No

a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=..

Answer / vaibhav

b=3
becoz in ternay operator if statement is true then it
returns non zero vaqlue othervise it return 0 in that case
we initialize the value of a is 0 therefore it will exicute
a else part

Is This Answer Correct ?    1 Yes 1 No

a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=..

Answer / simply rockz

in ternary operator a condition is required/// like..
<condition1>?<result1>:<result2>

b=(a=0)?2:3
so.. illegal use of ternary.../* "=" is an assignment operator*/

Is This Answer Correct ?    1 Yes 5 No

a=0; b=(a=0)?2:3; a) What will be the value of b? why b) If in 1st stmt a=0 is replaced by -1, b=..

Answer / ashwin kumar molugu

a)1st answer will be 3
in statement 1
b)if a=0 replaced with -1 its an error
in statement 2
c)if a=0 replaced with -1 2

answer is 2 becoz -1 is taken as true in c language

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More C Interview Questions

Is there any restriction in how many arguments printf or scanf function can take? in which file in my c++ compiler i can see the code for implementation of these two functions??

4 Answers  


What are the storage classes in C?

0 Answers  


what is const volatile?

2 Answers  


I have a function which accepts, and is supposed to initialize,a pointer, but the pointer in the caller remains unchanged.

1 Answers  


which operator having lowest precedence?? a.)+ b.)++ c.)= d.)%

4 Answers  


Toggle nth bit in a given integer - num

5 Answers   Qualcomm,


I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

0 Answers   TCS,


Where register variables are stored in c?

0 Answers  


How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

0 Answers  


Every time i run a c-code in editor, getting some runtime error and editor is disposing, even after reinstalling the software what may be the problem?

2 Answers  


when to use : in c program?

2 Answers  


What is difference between class and structure?

0 Answers  


Categories