Expressions and Interactivity PDF

Summary

This document explains programming concepts related to expressions, data types, and input/output in C++. It covers topics like operators, promotion, demotion, and type casting in the context of C++ programming.

Full Transcript

Expressions and Interactivity prompt - tells the user what to input cin object goes to next line bc the user must press enter to continue which automatically moves the cursor to the next line if two inputs side by side ex. cin>>f>>c; → th...

Expressions and Interactivity prompt - tells the user what to input cin object goes to next line bc the user must press enter to continue which automatically moves the cursor to the next line if two inputs side by side ex. cin>>f>>c; → the inputs should be separated by a space (any amount) on the user’s screen and then press enter (tokens: #s to be read) b is left to the keyboard buffer- 5 is int -.7 is double - 4 is char - *order matters in inputs An expression - a programming statement that has a value. operators follow PEMDAS → left to right (precedence) highest to lowest precedence: - (negative), division & multiplication& modulus, addition&subtraction An operator’s associativity is either left to right, or right to left. If two operators sharing an operand have the same precedence, they work according to their associativity assignment operator has lowest precedence right to left after assignment it will return the value type coercion - it strives to convert the operands to the same type promoted - When a value is converted to a higher data type demote - convert it to a lower data type Rule 1: chars, shorts, and unsigned shorts are automatically promoted to int. Rule 2: When an operator works with two values of different data types, the lower-ranking value is promoted to the type of the higher-ranking value. Rule 3: When the final value of an expression is assigned to a variable, it will be converted to the data type of that variable. A type cast expression lets you manually promote or demote a value static_cast(Value) C++ allows you to assign a value to multiple variables at once ex. a = b = c = d = 12; below is known as compound operator Expressions and Interactivity 1 formatting output setw() - manipulator cout

Use Quizgecko on...
Browser
Browser