Tokens | Bitwise Operators | Referencing Flashcards
What is a token in compiler construction?
A token is the smallest unit in a programming language that has meaning to the compiler, similar to words in a sentence.
What process breaks code into tokens?
Lexical analysis performed by a lexer breaks code into tokens.
Name the 5 main types of tokens in programming languages.
Keywords, Identifiers, Constants/Literals, Operators, and Punctuators/Special Symbols.
What is the purpose of keywords in programming?
Keywords are reserved words with special meaning that cannot be used as variable names.
Give three examples of identifiers in C++.
age, salary, and arr are valid identifiers.
What are literals/constants in programming?
Hardcoded values like integers (10), floats (3.14), characters (‘A’), and strings (“Hello”).
What operator categories exist in programming?
Arithmetic, Comparison, Logical, and Assignment operators.
What symbols are considered punctuators in C++?
Semicolon (;), commas (,), brackets ({}, (), []), and quotes (“).
What happens if you use a keyword as an identifier?
The compiler throws an error because keywords are reserved.
What is the difference between referencing and dereferencing?
Referencing (&) gets a variable’s memory address while dereferencing (*) accesses the value at that address.
What is the output of dereferencing a pointer containing 0x7ffcc3a8 if x=42?
It would output 42, the value stored at that memory address.
What real-world analogy explains pointers?
A pointer is like a note with a home address (memory address), where dereferencing is visiting the house (value).
Name three uses of referencing/dereferencing.
Efficient memory usage, dynamic allocation, and data structure implementation.
How many types of bitwise operators exist?
Six: AND (&), OR (|), XOR (^), NOT (~), Left Shift («), and Right Shift (»).
What is the result of 5 & 3 in bitwise operations?
00000101 & 00000011 = 00000001 (Decimal 1).
How does left shift operator affect numbers?
It multiplies by 2^n (e.g., 5 «_space;2 = 20).
What practical application uses num & 1?
Checking if a number is even (0) or odd (1).
How can bitwise operators swap variables without temp storage?
Using XOR: a = a^b; b = a^b; a = a^b;
What bitwise operation checks powers of two?
n & (n - 1) == 0 indicates a power of two.
What is two’s complement in bitwise NOT operations?
It’s how negative numbers are represented (e.g., ~5 = 11111010 = -6 in decimal).