Special Operators ????????????????? - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Special Operators ?????????????????

Description:

Special Operators Increment and decrement operators Conditional Operator – PowerPoint PPT presentation

Number of Views:48
Avg rating:3.0/5.0
Slides: 12
Provided by: W178
Category:

less

Transcript and Presenter's Notes

Title: Special Operators ?????????????????


1
Special Operators?????????????????
  • Increment and decrement operators
  • Conditional Operator

2
Conditional operators
  • ??????
  • expr1 ? expr2 expr3
  • ????????
  • ????????
  • scanf(01, i) ? printf(Valid input)
    printf(Invalid input)

????
????
???????????? expr1
???????????
expr2
expr3
3
????????
  • ???????????????????? ?????????????????????????????
    ????? 3 ?????
  • ?????????
  • ??????????????? (max)
  • ???????????? 3 ????? (a, b, c)
  • ?????????
  • ????????????????????????????
  • ??????

???????
????????????
??????????
4
???????? (???)
include ltstdio.hgt void main( ) int a, b,
c, max printf(Enter integer \na
) scanf(d, a) printf(b
) scanf(d, b) printf(c
) scanf(d, c) max (agtb) ? a b
(max lt c) ? maxc printf(The maximum is
d, max)
5
???????? (???)
????
????
a gt b
????
????
????
????
a gt c
b gt c
max c
max a
max b
max c
max (agtb) ? (agt c ? a c) (bgt c ? b c)
6
Increment decrement operators
  • ???????????????????????????? Integral types
    ????????
  • ?????????????????????????????????? 1 ?????
  • (Increment) ????????????????????? 1 ?????
  • ? n n 1 ? n 1 ? n ? n
  • -- (Decrement) ???????????????? 1 ?????
  • ? n n - 1 ? n - 1 ? n-- ? --n
  • Postfix operator ?????????????????????????????????
    ???????
  • Prefix operator ??????????????????????????????????
    ??????

7
????????
/ Demonstrate prefix and postfix increment
operator / include ltstdio.hgt void main()
int x , post 1, pre 1 x post
printf(x d\tpost d\n, x, post) x
pre printf (x d\tpre d\n, x,
pre) ????????????? run ????????????? x
1 post 2 x 2 pre 2
8
?????????????????????????????
( ) (postfix) --(postix) ????????? (unary)
-(unary) ! sizeof() (prefix) --(prefix)
????????? / ????????? -
????????? lt lt gt gt ?????????
! ????????? ?????????
????????? - /
?????????
????????????
??????????????
9
Arithmetic operators
??????????????????????????????????
int a1, b2, c3, d 4
?????? ???????????????
????????????
a b c-- 7 - -b d
((a) b) (c--) 1 7 ((-b)
(d)) 15
10
????????
int digits,
number for(digits 0 number gt 0 digits
1) number / 10 for
(digits0 numbergt0 number / 10,
digits) for (digits0 numbergt0 digits)
number / 10 for (digits0 numbergt0 number /
10, digits)
11
???????????????????????????????
  • int i, n
  • for (i8, n50 n ! 1 i)
  • n (n 2 0) ? n / 2 3 n 1
  • if (i 6 0)
  • printf(\n)
  • printf(d , n)
  • printf(No. of hailstones generated d\n, i)
Write a Comment
User Comments (0)
About PowerShow.com