IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Expressions - Discussion

@ : Home > C Programming > Expressions > General Questions - Discussion

Read more:

"It takes a very long time to become young."
- Pablo Picasso
3. 

Which of the following is the correct usage of conditional operators used in C?

[A]. a>b ? c=30 : c=40;[B]. a>b ? c=30;
[C]. max = a>b ? a>c?a:c:b>c?b:c[D]. return (a>b)?(a:b)

Answer: Option E

Explanation:

Option A: assignment statements are always return in paranthesis in the case of conditional operator. It should be a>b? (c=30):(c=40);

Option B: it is syntatically wrong.

Option D: syntatically wrong, it should be return(a>b ? a:b);

Option C: it uses nested conditional operator, this is logic for finding greatest number out of three numbers.


Souravb said: (Sun, Jul 11, 2010 02:32:47 AM)    
 
I cant understand it. Please help.

Afsheen said: (Mon, Jul 19, 2010 02:24:33 AM)    
 
If b>c then b is true else c is true, so 1st b>c is evaluated and stored then a>c is evaluated and stored. now the whole expression is considered.

Let us assume

(i) in b>c case this stmnt is true so b is saved.
(ii)in a>c case this stmnt is false so c is saved.
now the expression is in the form
max=a>b?c:b

Now finally this is evaluated.
you just assume the given stmnt as a>b?(a>c?a:c):(b>c?b:c).

I hope you understood.

Durga said: (Wed, May 11, 2011 02:36:05 AM)    
 
I am not under stand please clear about it. In detailed because I don't know how to use ? opearator. So plese clear with a example how to use this operator.

Ramu said: (Mon, Aug 1, 2011 10:19:58 PM)    
 
Simply we have to think in general if..else format

like if(a>b)
{
if(a>c)
max is a
else
max is c
}
else if(b>c)
max is b
else
max is c

This is implemented , thinking in this we could easily analyse for greatest of 3 or 4 or 5 and so on easily I think so.

Vishwas Pathak said: (Sun, Aug 28, 2011 06:07:48 PM)    
 
Option A is also right i did it in the dev-c++ and i got first one as the answer.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!