C++ Type Casting, Arithmetic Rules, and I/O (Lecture Notes)

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/21

flashcard set

Earn XP

Description and Tags

Vocabulary flashcards covering C++ type rules, casting, overflow, and I/O basics from the lecture notes.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

22 Terms

1
New cards

Integer arithmetic

When both operands are integers; division truncates toward zero, discarding any fractional parts.

2
New cards

Floating-point promotion

If at least one operand is floating point (float, double, long double), the entire operation is promoted to floating point to preserve fractions.

3
New cards

Usual arithmetic conversions

Rules that determine the resulting type in mixed-type expressions; the stronger type wins (double > float > integer).

4
New cards

Implicit casting

Compiler automatically promotes or converts types during evaluation without explicit syntax.

5
New cards

Explicit casting

You manually request a type change using a cast; examples include static_cast(x).

6
New cards

static_cast

A C++ explicit cast that converts a value to a target type; used to forcibly change a value's type.

7
New cards

Overflow

When a value cannot fit in the available bits of the data type; results can wrap around or become incorrect; may require a larger type.

8
New cards

Large-number guideline

If a quantity is around 2,000,000,000 or larger, avoid int; use a larger type like long int or double instead.

9
New cards

Left-to-right evaluation

C++ evaluates expressions from left to right and applies type rules at each step.

10
New cards

Post-increment

x++ returns the current value, then increments x after the expression is evaluated.

11
New cards

Pre-increment

++x increments x first, then the new value is used in the expression.

12
New cards

IO streams

C++ console I/O uses std::cin (input), std::cout (output), and std::cerr (error); these are buffered.

13
New cards

cout

Standard output stream; used with the << operator to print to the console.

14
New cards

cin

Standard input stream; used with the >> operator to read from the console; reads until whitespace.

15
New cards

cerr

Standard error stream; separate from normal output for error messages.

16
New cards

using namespace std

Directive to bring standard library names into the global namespace; commonly placed at the top of a file.

17
New cards

include directive

Preprocessor command to copy header declarations into your file; standard headers use angle brackets <>; user headers use quotes.

18
New cards

header guards

Preprocessor technique (#ifndef, #define, #endif) to prevent multiple inclusions of the same header.

19
New cards

std::string

Standard string type from the string library; dynamic, safe for text handling.

20
New cards

String concatenation

Operator + merges two std::string objects into one string.

21
New cards

Extraction operator (>>)

Reads input from standard input into a variable; stops at whitespace; to read multiple words, chain extractions.

22
New cards

Output operator (<<)

Writes data to standard output via std::cout; used with strings and values.