Partial preview of the text
Download Assignment and Modules and more Study notes Computer Programming in PDF only on Docsity!
Module 5: Operators » a clearer idea of C's: Objectives: — Having read this module the students should have a cle of e Arithmetic Operators ® Prefix / Postfix Operators e Assignment Operators Relational Operators Logical or Boolean Operators Ternary Operators Precedence and Associativily of Operators * © s «s C Operators C supports almost common arithmetic operators. Arithmetic set Sample Expression () Brackets (A+B-C)*D | Brackets * Multiplication A*B . A times B / Division A/B A divided by B +. _| Addition A+B A plus B - {Subtraction A- 8B A minus B 1% Modulus A % B A modulus B i= Assignment A=B A gets the value of B The program below demonstrates how arithmetic operators are used in C programs. #include main () { int x = 10, y = 20; int result = 0; printf ("x = %d\n",x); print£("y = %d\n",y); result = y + x; _ /* demonstrate = operator + */ printf ("result = y + x; result = %d\n", result); result = result ~ 2; — /* damonstrata - oparator */ printf ("result = result - 2; result = td\n", rasult); result = result * 5; | /* demonstrate * operator */ printf (reault = result * 5; result = %d\n", result); result = result / 5; /* demonstrate / operator */