FIND YOUR NEXT FEW LINES

Results for “extra”

Small, practical examples. Search by task or narrow things down below.

301 snippets foundClear filters
CStructures & function interfaces

Group related values in nested structures

C: Nested members model a record that owns another simple record.

C✓ Tested
CDynamic memory & ownership

Grow an allocation without losing it on failure

C: Assign realloc to a temporary pointer so the original allocation remains available if growth fails.

C✓ Tested
C++Filesystem operations

Handle a failed file open through stream state

C++: An unopened input stream is not an empty successful file read.

C++✓ Tested
C++Numeric parsing & calculations

Handle a failed string-to-integer conversion

C++: stoi throws invalid_argument when no conversion can be performed.

C++✓ Tested
CFile positioning & lifecycle

Handle a missing file without treating it as an empty file

C: Inspect errno after a failed fopen to distinguish the documented missing-path condition.

C✓ Tested
C++Getting Started

Handle three possible outcomes

C++: Check high, normal and low values with an ordered conditional chain.

C++✓ Tested
CGetting Started

Handle three possible outcomes

C: Check high, normal and low values with an ordered conditional chain.

C✓ Tested
C++Tasks & synchronization

Increment a shared counter safely

C++: Atomic increments prevent lost updates when two threads change the same counter.

C++✓ Tested
CDynamic memory & ownership

Initialize a byte buffer to zero

C: memset initializes each byte to the chosen unsigned-char value.

C✓ Tested
CStructures & function interfaces

Initialize structure fields by name

C: Designated initializers make field assignments independent of their declaration order.

C✓ Tested
C++Containers & compound values

Insert a map value only when a key is absent

C++: try_emplace preserves the old value when insertion does not take place.

C++✓ Tested
CArray transformations

Insert into an array with spare capacity

C: Move the trailing elements before inserting and keep the logical length separate from capacity.

C✓ Tested