Tokens | Bitwise Operators | Referencing Flashcards

1
Q

What is a token in compiler construction?

A

A token is the smallest unit in a programming language that has meaning to the compiler, similar to words in a sentence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What process breaks code into tokens?

A

Lexical analysis performed by a lexer breaks code into tokens.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name the 5 main types of tokens in programming languages.

A

Keywords, Identifiers, Constants/Literals, Operators, and Punctuators/Special Symbols.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of keywords in programming?

A

Keywords are reserved words with special meaning that cannot be used as variable names.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give three examples of identifiers in C++.

A

age, salary, and arr are valid identifiers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are literals/constants in programming?

A

Hardcoded values like integers (10), floats (3.14), characters (‘A’), and strings (“Hello”).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What operator categories exist in programming?

A

Arithmetic, Comparison, Logical, and Assignment operators.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What symbols are considered punctuators in C++?

A

Semicolon (;), commas (,), brackets ({}, (), []), and quotes (“).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens if you use a keyword as an identifier?

A

The compiler throws an error because keywords are reserved.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between referencing and dereferencing?

A

Referencing (&) gets a variable’s memory address while dereferencing (*) accesses the value at that address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the output of dereferencing a pointer containing 0x7ffcc3a8 if x=42?

A

It would output 42, the value stored at that memory address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What real-world analogy explains pointers?

A

A pointer is like a note with a home address (memory address), where dereferencing is visiting the house (value).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Name three uses of referencing/dereferencing.

A

Efficient memory usage, dynamic allocation, and data structure implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How many types of bitwise operators exist?

A

Six: AND (&), OR (|), XOR (^), NOT (~), Left Shift («), and Right Shift (»).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the result of 5 & 3 in bitwise operations?

A

00000101 & 00000011 = 00000001 (Decimal 1).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does left shift operator affect numbers?

A

It multiplies by 2^n (e.g., 5 &laquo_space;2 = 20).

17
Q

What practical application uses num & 1?

A

Checking if a number is even (0) or odd (1).

18
Q

How can bitwise operators swap variables without temp storage?

A

Using XOR: a = a^b; b = a^b; a = a^b;

19
Q

What bitwise operation checks powers of two?

A

n & (n - 1) == 0 indicates a power of two.

20
Q

What is two’s complement in bitwise NOT operations?

A

It’s how negative numbers are represented (e.g., ~5 = 11111010 = -6 in decimal).