Undefined Behavior and Pitfalls interview questions
15 real Undefined Behavior and Pitfalls questions from the C++ bank, as asked in Indian campus drives and tech interviews. Every question has a verified answer and an AI-tutor explanation on placd — free to start.
1. What is Undefined behavior?
Junior
A.a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
B.an alias still naming an object whose lifetime has ended, such as returning a reference to a local variable, making use of it invalid
C.writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
D.accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
2. Which term means: "a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly"?
A.Undefined behavior — an alias still naming an object whose lifetime has ended, such as returning a reference to a local variable, making use of it invalid
B.Undefined behavior — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
C.Undefined behavior — a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
D.Undefined behavior — writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
5. Which term means: "an alias still naming an object whose lifetime has ended, such as returning a reference to a local variable, making use of it invalid"?
A.Dangling reference — an alias still naming an object whose lifetime has ended, such as returning a reference to a local variable, making use of it invalid
B.Dangling reference — a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
C.Dangling reference — accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
D.Dangling reference — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
A.Narrowing conversion — accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
B.Narrowing conversion — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
C.Narrowing conversion — a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
D.Narrowing conversion — writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
11. Which term means: "writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results"?
A.Buffer overflow — a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
B.Buffer overflow — writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
C.Buffer overflow — an alias still naming an object whose lifetime has ended, such as returning a reference to a local variable, making use of it invalid
D.Buffer overflow — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
14. Which term means: "accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws"?
A.Use after free — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
B.Use after free — an alias still naming an object whose lifetime has ended, such as returning a reference to a local variable, making use of it invalid
C.Use after free — writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
D.Use after free — accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
Answers, AI explanations, and a scored voice mock interview
Sign up free to check your answers with explanations, ask the AI tutor anything on any question, and take one full AI mock interview — scored like a real panel.