STANDARD OPERATIONS AND FUNCTIONS Arithmetic Operations Operation Order Increment and Decrement Operators Assignment Operators Boolean Operations Logical Operators Standard Functions String Functions Arithmetic Operations add + subtract - multiply * divide / remainder % force = mass * accel; average = total / SIZE; r = x + y*z - q/h; 11 / 3 is 3 11.0 / 3 is 3.6667 11 % 3 is 2 Can perform arithmetic operations on character data Operation Order Within parentheses *, /, % left-to-right +, - left-to-right Good rule of thumb: Use Parentheses! s = t / (a + s * (x-z)) + q; Increment and Decrement Operators increment ++ decrement -- int, float, char ++count; // count = count + 1; --drop; // drop = drop - 1; ++x ... pre-increment x++ ... post-increment Suppose x=7, y=5... a = ++x; // x=8, a=8 b = y++; // y=6, b=5 Pre/post-decrement work same way ``C++ = language one better than C'' Assignment Operators = simple assignment += addition assignment slug += zig*zag; // slug = slug + zig*zag; -= subtraction assignment drop -= few; // drop = drop - few; *= multiplication assignment /= division assignment Boolean Operators Boolean Operators result in false true == equal to (sum == SIZE) result is 1 if sum equal SIZE result is 0 if sum not equal SIZE does not change sum or SIZE Be very careful! (sum = SIZE) changes sum to SIZE result is SIZE (false if 0, true otherwise) != not equal to (sum != SIZE) < less than (sum < SIZE) <= less than or equal to > greater than >= greater than or equal to Logical Operators ! not !(sum > SIZE) || or (sum = SIZE) || (flag > stopper) && and Standard Functions #include #include #include abs(x) -- absolute value of x cos(x) -- cosine of x pow(x,y) -- x to the y power rand() -- random number sqrt(x) -- square root of x String Functions #include char bob[20]; char job[10]="Sales"; char mob[10]="person"; char rob[20]; bob = job; // doesn't really work just copies address if change job, changes bob as well strcpy(bob,job); // bob is now "Sales" strcat(bob,mob); // bob is now "Salesperson" strcmp(bob,rob) -- is bob same as rob?