What is the difference between a vector's size() and its capacity()?
size() is the number of elements currently in use. capacity() is how many elements the currently-allocated block can hold before it must reallocate. Capacity is usually ≥ size and grows in chunks (often doubling), so not every push_back triggers a reallocation. std::array has only a fixed size — no separate capacity.
A C-style string (const char*) describing the error — the exception's message. For std::out_of_range from .at(), it includes details such as the bad index and the container size.
Which permission bit is the usual culprit behind 'Permission denied' when running ./script.sh?
The execute (x) bit. Without it, the shell won't run the file even if it's readable. Fix with chmod +x script.sh. (For a script you also need a readable interpreter, but the missing x is the classic cause.)
What numeric permission mode does -rwxr-xr-x correspond to?
755. Ignore the leading - (it just marks a regular file; d would be a directory). Read the three triplets with r=4, w=2, x=1: owner rwx = 4+2+1 = 7, group r-x = 4+0+1 = 5, others r-x = 5 → 755.
On a directory, what do r, w, and x each mean (they differ from a file)?
On a directory: r = list the names inside it; w = add/remove/rename entries (create or delete files in it); x = enter/traverse it (cd into it and reach files by name). Notably you need x on a directory just to reach files inside it, even if you already know their paths.
An array must be contiguous. Where is that actually guaranteed?
In virtual address space.arr[i] is computed from virtual addresses, so they must be continuous. The physical frames behind the pages can be scattered; the page table maps them.
int a[n]; with a runtime n compiles silently on g++. Which flag makes g++ warn that it is not standard C++?
-pedantic (or -pedantic-errors to make it an error). -Wall, -Wextra, -O2 and picking a newer -std= do not mention the VLA, because g++ allows it as an extension.
The MMU (Memory Management Unit) is dedicated hardware in the CPU that translates a virtual address into a physical address on every memory access — by walking the page table (or hitting the TLB) — and simultaneously checks the permission bits (present? writable? executable?), raising a page fault or protection fault if something is wrong. Software sets up the page tables; the MMU reads them and translates automatically.
int n = getInput();
constint a = n;
constexprint b = n;
constexprint c = 42;
a and c compile; b is an error. const int a = n; is fine — const only means 'won't change after init', and initializing it from a runtime value is legal. constexpr int b = n; fails because constexpr demands a value known at compile time, but n came from runtime input. constexpr int c = 42; is fine — 42 is a compile-time constant.
What is the difference between a page and a frame?
A page is a fixed-size chunk of the program's content (a slice of code/heap/stack) — think of a chapter torn from a book. A frame is a fixed-size slot in physical RAM — a shelf slot that holds one page. They're the same size, and exactly one page fits in one frame. 'Page 3 is in frame 47' means page 3's actual bytes are stored in that physical frame.
This program prints 4 and exits cleanly. Is it correct?
C++
std::array<int,5> a;
a[10] = 4;
cout << a[10];
No — it is undefined behaviour.a has valid indices 0–4, but you write to index 10. std::array::operator[] does no bounds checking, so it just computes an out-of-bounds address and writes there. It happened not to crash and printed 4, but that's luck — the same code could crash, corrupt another variable, or behave differently on another compiler/run. 'It printed 4' is not proof of correctness.
Which command changes only the group of data.txt to devs?
chown :devs data.txt: the empty part before the colon leaves the owner unchanged. (chgrp devs data.txt does the same.) chown devs data.txt would change the owner.
What is the difference between chmod 755 f and chmod +x f?
chmod 755 f sets all three triplets explicitly and absolutely — owner rwx, group r-x, others r-x — overwriting whatever was there. chmod +x f is relative: it only adds the execute bit (for all three categories) and leaves the read/write bits untouched. Use numeric for an exact mode; symbolic to nudge one bit.
True or false: paging suffers from external fragmentation.
False. Any free frame can hold any page, so gaps between allocations never block a request. Paging trades that for a little internal fragmentation in the last page.