C++ Variables, Data types, Operators, Expressions

Cards (14)

  • Variables are named containers that store values in memory for later use and must be declared with a data type before use.
  • Variables must consist of letters, digits, and underscores and cannot start with a digit.
  • Variables are case-sensitive, for example, Age and age are different.
  • Variables cannot use any of the C++ reserved keywords as variable names.
  • Data Types specify the kind of data a variable can hold, determining its size and operations allowed.
  • Common Data Types include Integers, Floating-point numbers, Characters, Strings, and Booleans.
  • Operators are symbols that perform operations on values and variables.
  • Types of Operators include Arithmetic operators, Comparison operators, Logical operators, and Assignment operators.
  • Expressions are combinations of values, variables, and operators that produce a result and are evaluated according to operator precedence.
  • Operators have different levels of precedence, determining the order in which they're evaluated within an expression.
  • Operators with higher precedence are evaluated before those with lower precedence.
  • The general order of precedence from highest to lowest is Scope Resolution (::) Member Access (., .*) Postfix () [] -> ++ -- *Unary + - ! ~ ++ -- (type) * sizeof & ** Multiplicative * / % Additive + -Shift << >> Relational < <= > >= Equality == != Bitwise AND & Bitwise XOR ^ Bitwise OR | Logical AND && Logical OR || Conditional ?: *Assignment = += -= = /= %= &= ^= |= <<= >>= Comma ,.
  • When multiple operators with the same precedence appear in an expression, associativity determines the order of evaluation.
  • There are two types of associativity: Left-to-right: Operators are evaluated from left to right and Right-to-left: Operators are evaluated from right to left.