It's undefined behavior. The C++ standard doesn't define what happens if you do that.
From the C++14 standard draft N4296, §1.3.24:
Permissible undefined behavior ranges from ignoring the situation
completely with unpredictable results, to behaving during translation
or
program execution in a documented manner characteristic of the environment(with or without the issuance of
a diagnostic message), to terminating a translation or execution (with
the issuance of a diagnostic message).
You may go one level beneath the standard, i.e., the operating system, which, besides other stuff, takes care of memory management.
The buffer name
is allocated on the stack, next to stack frames, automatic variables, and thread-local variables.
When calling cin.get(name, 30)
, data may be written over the array's boundaries, effectively overwriting the data I enumerated. It may even happen that the call attempts to write over stack boundaries, which would almost certainly be caught by the OS.