C++ Deck 1 Flashcards
What is the definition of lexical elements in C++?
Words, names, symbols, etc. that are part of the lexicon of the programming language. They’re the items that a program can understand as a part of a valid statement.
What are keywords?
Particular words that have a definitive meaning and purpose in C++, e.g. - namespace
aka “Reserved Words”
What are directives?
Specific instructions given to the C++ compiler to perform actions like including libraries, defining constants, etc. e.g. - #include
What are identifiers?
Names given by the programmer to programmatic or storage elements to make our task easier, e.g. - “number” (or some other variable or function name)
What are literals?
Values directly specified in the program, e.g. - 10, 25, etc. sometimes referred to as “hardcoded”
A location in memory associated with a name that can store ONE value. It also has a data type that specifies what type of information it can store and how it is formatted in memory.
Variable
True or False: An operator is a lexical element.
True
What are the operation, operator, and operand in this statement: x + y
operation: addition
operator: +
operands: x, y
What are the operation, operator, and operand in this statement: 15 - 12
operation: subtraction
operator: -
operands: 15, 12
What are the operation, operator, and operand in this statement: z * 9
operation: multiplication
operator: *
operands: z, 9
What is an arity in C++?
The number of arguments or operands taken by a function, operation, or relation.
What is a Unary operator?
An operator that uses exactly 1 operand.
What is a Binary Operator?
Operators that take 2 operands (even if that’s not obvious at first glance.)
The most common arity for C++ operators.
What are Ternary Operators?
These operators use exactly 3 operands. The conditional operator (?:) and the spaceship operator (<=>) are examples. Not covered in-depth during these chapters.
Is -20 Unary, Binary or Ternary?
Unary
There is only one operand (20) and the operator is the negative sign (also known as unary minus)
Is ++ a Unary, Binary, or Ternary operator?
Unary. It increments the value of whatever it pre- or -post increments.
Is “value + number” Unary, Binary, or Ternary?
Binary. There are two operands (value, number)
Is X = 51 Unary, Binary, or Ternary?
Binary. There are two operands (x, 51)
Is cout«num Unary, Binary, or Ternary?
Binary. There are two operands (cout, num)
What is the arity of the»_space; (extraction) operator used in a cin statement?
Binary. It uses two operands (the input, then the variable where the input is subsequently stored)
What is cascading?
When an operator appears several times in the same statement, i.e. cout«x«y«z (outputs all 3 values in the order they appear from left to right)
What is operator precedence?
The order in which C++ evaluates operators in a given statement containing multiple operators.
What is left and right associativity?
When two operators have the same precedence, their associativity determines which order they will be evaluated in.
Left associativity is evaluated from left-to-right, Right associativity is evaluated from right-to-left.
What is the name of this operator: =
Assignment Operator