ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
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=?
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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=?
Answer
# 1
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 ?    1 Yes 1 No
Syamkumarm
 
  Re: 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=?
Answer
# 2
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 ?    0 Yes 2 No
Simply Rockz
 
 
 
  Re: 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=?
Answer
# 3
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 ?    2 Yes 0 No
Ashwin Kumar
 
  Re: 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=?
Answer
# 4
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 ?    1 Yes 1 No
Vignesh1988i
 
  Re: 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=?
Answer
# 5
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 ?    0 Yes 0 No
Vaibhav
 
  Re: 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=?
Answer
# 6
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 0 No
Ashwin Kumar Molugu
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
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=? Geometric-Software6
array contains zeros and ones as elements.we need to bring zeros one side and one other side in single parse. ex:a[]={0,0,1,0,1,1,0,0} o/p={0,0,0,0,0,1,1,1} Motorola7
write a 'c' program to sum the number of integer values  5
Why data types in all programming languages have some range? Why ritche have disigned first time likethat?Why not a single data type can support all other types? Excel1
write a c program to check weather a particluar bit is set or not? IBM4
How can I call a function, given its name as a string? ABC-Telecom2
I have a function which accepts a pointer to an int. How can I pass a constant like 5 to it?  3
wite a programme in c to linear search a data using flag and without using flags? TCS3
which type of question asked from c / c++ in interview.  2
main() { int x=10,y=15; x=x++; y=++y; printf("%d %d\n",x,y); } output?? Ramco13
What is the memory allocated by the following definition ? int (*x)[10]; ADITI3
who is the founder of c HP9
c programming of binary addition of two binary numbers  1
write the program for maximum of the following numbers? 122,198,290,71,143,325,98  4
Find Error if any in below code, Justify ur answer: struct xx { int a; struct yy { char c; struct xx* p; } struct yy* q; } NDS3
Write a C program to print 1 2 3 ... 100 without using loops?  5
what is the output of the following program? main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }  7
Hi, main() { } Is a user defined function or Built in Functionn Honeywell9
what is the difference between #include<> and #include”…”?  1
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it?  3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com