PJC Flashcards

(18 cards)

1
Q

Used for output and input in C++, respectively
Found in the <iostream> header</iostream>

A

std::cout and std::cin

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

Mostly the same (e.g., if, else, for, while)
Exception: return is not always required in C++, leading to potential Undefined Behavior

A

Control Flow in C++ vs. Java

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

Behavior that is unpredictable and can cause crashes or unexpected results
Should be avoided at all costs
Often caused by breaking C++ rules

A

Undefined Behavior (UB)

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

Used for type inference (compiler determines the type)
Advantages:
Safety (prevents uninitialized variables)
Conciseness (shorter code)
Uniformity
Performance

A

auto keyword

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

Instructions for the preprocessor (runs before compilation)
#include: Inserts the contents of a file
#define: Creates macros (text replacements)

A

Preprocessor Directives

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

Java uses “collections” (e.g., List, Set)
C++ uses “containers” (e.g., vector, set)
Both refer to types that store multiple elements

A

Collections vs. Containers

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

Used to get the number of elements in a container
Consistent across arrays, strings, and other containers

A

size() in C++

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

Function: Named block of code that takes parameters and returns a value
Method: Function that is part of a class (member function)

A

Function vs. Method

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

Argument: Value passed to a function
Parameter: Variable declared in the function signature that receives the argument

A

Argument vs. Parameter

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

.clear(): Removes all elements
.empty(): Returns true if the container is empty

A

Additional Container Methods

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

Most algorithms modify the original container in place (e.g., std::ranges::sort())
Some algorithms return a result (e.g., std::ranges::equal())

A

Values Returned by Standard Algorithms

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

New algorithms use std::ranges namespace (e.g., std::ranges::sort())
Old algorithms don’t use std::ranges (e.g., std::sort())
Prefer new algorithms when available

A

Old vs. New Algorithms

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

No built-in easy way in standard C++ before C++23
External libraries can help (will be covered later)

A

Displaying a Range

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

Shortens code by avoiding repeated std::
Can lead to errors if overused
Use cautiously, preferably within functions

A

using Directive

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

Alternative to using directive
Creates a shorter name for a namespace (e.g., namespace rng = std::ranges;)
Can be used globally in .cpp files

A

Namespace Alias

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

Used for dynamic memory allocation (creating objects on the heap)
Avoid until you understand pointers

17
Q

Use them whenever possible for better code
Understand how they work and why to choose one over another

A

Standard Algorithms

18
Q

Makes a variable or object immutable (cannot be changed)
Use by default for safety and clarity
Its absence should raise a “yellow flag”

A

const Keyword