Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CONDITIONAL OPERATOR ( ? : ) or Ternary Operator
- >> It Requires 3 Argument Arg1 ? Arg2 : Arg3
- >> If Arg1 is true, Whole statement is replacement by Arg2.
- Arg1(True) ? Arg2 : Arg3 >>>>>>> Arg2
- >> If Arg1 is False, Whole statement is replacement by Arg3.
- Arg1(False) ? Arg2 : Arg3 >>>>>>> Arg3.
- True = Non-Zero
- False = Zero
- a= 15?1:2 ; 1
- a=10.5?45:78; 45
- a= 0?1:2; 2
- a=3+0?23:43; 23
- a= 10 ?20:30; 20
- a= 100?0:200; 0
- a=1.5 ? 100:200; 100
- a=0?1.2:300; 300
- a=3?10:20; 10
- a= 3+0?10:20; 10
- a=5?10+5:5+15; 15
- a=0?5+3:2-5; -3
- Priority
- 1. ! Unary
- 2. * / % Binary
- 3. + - Binary
- 4. > < >= <= Binary
- 5. == != Binary
- 6. && Binary
- 7. || Binary
- 8. ?: Ternary
- 9. = Binary
- if(a>b)
- {
- max=a;
- }
- else Conditional >>> max= b>a(False)?b :a; max=a;
- { Bitwise Operator>>> max=a+((a-b)>>15)*(a-b);
- max=b;
- }
- if(a>b && a>c)
- {
- max=a; max= a>b&&a>c ?a : b>c ? b : c;
- } max= a>b&&a>c?a:b>c?b:c;
- else
- {
- if(b>c)
- {
- max=b;
- else
- {
- max=c;
- }
- }
- max= a>b&&a>c? a:b>c?b:c;
- a= 8>3?4>7?10:4>7?9>10?20:30:4>7?40:50:6>8?9>1?10:70:80; 50
- Step 1: Count No. of ? and : . If both are Equal then go to next step
- Step 2: Goto 1st ( : ) and Match to the nearest left ( ? ) and Repeat
- Step 3: All ? and : Matched then there is no error
- a=6>8?2>1?10:3>2?20:30:6>4?4>8?40:6>2?50:60:70; 50
- if(x>y)
- {
- printf("A");
- printf("B"); Statement
- }
- else
- {
- printf("C");
- printf("D");
- }
- x>y ? printf("A");printf("B");:printf("C");printf("D");; Invalid
- Arg1? Arg2 : Arg3; Syntax
- Note : Every Conditional opr can be converted to if else but vice versa not possible.
- a=10,b=20;
- c = a && b = 30;
- printf("%d %d %d",a,b,c); lvalue
- *****************************************
Add Comment
Please, Sign In to add comment