Looking for a Tutor Near You?

Post Learning Requirement »
x
x

Direction

x

Ask a Question

x

Hire a Tutor

PPT On C++ - Operators And Operations

Loading...

Published in: C / C++
3,741 Views

A study of these C++ ppts will help the student get an idea about the fundamental concepts in c++. Very useful for 11, 12th grade CBSE students who have taken c++ in computer science. This ppt is about Operators and Operations.

Prerna S / Sharjah

4 years of teaching experience

Qualification: B.E in computer Science

Teaches: GRE, SAT, ACT, Maths, MS Office, Web Development, HTML, Java, English, Hindi, Science, Chemistry, Computer Science, Mathematics, English Language

Contact this Tutor
  1. Operators
  2. Boolean values ' Boolean variables are variables that can have only two possible values: true (1), and false (O). ' To declare a boolean variable, we use the keyword bool. ' To initialize or assign a true or false value to a boolean variable, we use the keywords trueand false ' bool bl = true; // copy initialization ' bool b2(false); // direct initialization b3 = false; // assignment ' If you want cout to print "true" or "false" instead of O or 1, you can use boolalpha: cout
  3. Example in if else statement bool b(false); if (b) std::cout
  4. Const, constexpr, and symbolic constants ' To make a variable constant, simply put the const keyword either before or after the variable type. ' const double gravity { 9.8 }; // preferred use of const before type ' int const sideslnSquare { 4 }; // okay, but not preferred
  5. Operator precedence and associativity ' an operation is a mathematical calculation involving zero or more input values (called operands) that produces an output value. Common operations (such as addition) use special symbols (such as +) that denote the operation. These symbols are called operators. ' l*parenthesis ' 2-->increment /decrement ' 5-->comparison < > , or ' Etc these are most important predecence
  6. Unary arithmetic operators ' There are two unary arithmetic operators, plus (+), and minus (-). The unary plus operator returns the value of the operand. In other words, +5 = 5, and +x = x. ' The unary minus operator returns the operand multiplied by -1. In other words, if x = 5, -x = -5.
  7. Binary arithmetic operators Operator Addition Subtraction Multiplication Division Modulus (Remainder) Symbol Form Operation x plus y x minus y x multiplied by y x divided by y The remainder of x divided by y
  8. Modulus (remainder) ' Practise :create a program which returns Boolean value true if the number is even and false if it odd using modulus operator
  9. Arithmetic assignment operators Operator Assignment Addition assignment Subtraction assignment Multiplication assignment Division assignment Modulus assignment Symbol Form Operation Assign value y to x Add y to x Subtract y from x Multiply x by y Divide x by y Put the remainder of x / y in x
  10. Increment/decrement operators Operator Prefix increment (pre- increment) Prefix decrement (pre- decrement) Postfix increment (post- increment) Postfix decrement (post- decrement) Symbol Form —x x— Operation Increment x, then evaluate x Decrement x, then evaluate x Evaluate x, then increment x Evaluate x, then decrement x
  11. The prefix increment/decrement operators are very straightforward. The value of x is incremented or decremented, and then x is evaluated int x = 5; int y = ++x; // x is now equal to 6, and 6 is assigned to y The postfix increment/decrement operators are a little more tricky. The compiler makes a temporary copy of x, increments or decrements the original x (not the copy), and then evaluates the temporary copy of x. The temporary copy of x is then discarded. ' int x = 5; ' int y = x++; // 5 is assigned to y, and x is now equal to 6
  12. Find the output ' int x = 5, y = 5; y Inl; ' std::cout
  13. Sizeof, comma, and conditional operators Operator Sizeof Symbol sizeof #include int main() double d = 5.0; Form sizeof(type) sizeof(variable) Operation Returns size of type or variable in bytes std::cout
  14. Conditional operator Operator Conditional Symbol Form Operation If c is nonzero (true) then evaluate x, otherwise evaluate y If/else statements in the following form: if (condition) expression; other expression; can be rewritten as: (condition) ? expression other expression;
  15. Relational operators (comparisons) Operator Greater than Less than Greater than or equals Less than or equals Equality Inequality Symbol Form Operation true if x is greater than y, false otherwise true if x is less than y, false otherwise true if x is greater than or equal to y, false otherwise true if x is less than or equal to y, false otherwise true if x equals y, false otherwise true if x does not equal y, false otherwise
  16. Practice ' Write a program to take 2 values as input from the user and compare and display them (make use of all the relational operators)
  17. Logical operators Operator Logical NOT Logical AND Logical OR Symbol Form !x x Il Y Operation true if x is false, or false if x is true true if both x and y are true, false otherwise true if either x or y are true, false otherwise Practice:write a program to get a input from the user and then evaluate whether it is more than 50 or les than ;more than 50 and less than 100 ,and it should not be equal to 55