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
  1. A.a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
  2. 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
  3. C.writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
  4. D.accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
Reveal the answer + AI explanation — free account

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"?

Junior
  1. A.Use after free
  2. B.Undefined behavior
  3. C.Buffer overflow
  4. D.Dangling reference
Reveal the answer + AI explanation — free account

3. Which statement is correct?

Junior
  1. 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
  2. B.Undefined behavior — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
  3. C.Undefined behavior — a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
  4. D.Undefined behavior — writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
Reveal the answer + AI explanation — free account

4. What is Dangling reference?

Mid
  1. A.an alias still naming an object whose lifetime has ended, such as returning a reference to a local variable, making use of it invalid
  2. B.an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
  3. C.a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
  4. D.accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
Reveal the answer + AI explanation — free account

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"?

Mid
  1. A.Use after free
  2. B.Narrowing conversion
  3. C.Buffer overflow
  4. D.Dangling reference
Reveal the answer + AI explanation — free account

6. Which statement is correct?

Mid
  1. 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
  2. B.Dangling reference — a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
  3. C.Dangling reference — accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
  4. D.Dangling reference — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
Reveal the answer + AI explanation — free account

7. What is Narrowing conversion?

Mid
  1. A.an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
  2. 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
  3. C.a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
  4. D.accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
Reveal the answer + AI explanation — free account

8. Which term means: "an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time"?

Mid
  1. A.Narrowing conversion
  2. B.Undefined behavior
  3. C.Dangling reference
  4. D.Use after free
Reveal the answer + AI explanation — free account

9. Which statement is correct?

Mid
  1. A.Narrowing conversion — accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
  2. B.Narrowing conversion — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
  3. C.Narrowing conversion — a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
  4. D.Narrowing conversion — writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
Reveal the answer + AI explanation — free account

10. What is Buffer overflow?

Senior
  1. A.an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
  2. 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
  3. C.writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
  4. D.a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
Reveal the answer + AI explanation — free account

11. Which term means: "writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results"?

Senior
  1. A.Undefined behavior
  2. B.Buffer overflow
  3. C.Dangling reference
  4. D.Narrowing conversion
Reveal the answer + AI explanation — free account

12. Which statement is correct?

Senior
  1. A.Buffer overflow — a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
  2. B.Buffer overflow — writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
  3. 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
  4. D.Buffer overflow — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
Reveal the answer + AI explanation — free account

13. What is Use after free?

Mid
  1. A.accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
  2. B.a program condition for which the standard imposes no requirements, permitting the compiler to assume it never happens and optimize accordingly
  3. C.writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
  4. D.an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
Reveal the answer + AI explanation — free account

14. Which term means: "accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws"?

Mid
  1. A.Dangling reference
  2. B.Buffer overflow
  3. C.Undefined behavior
  4. D.Use after free
Reveal the answer + AI explanation — free account

15. Which statement is correct?

Mid
  1. A.Use after free — an implicit conversion that may lose information, such as double to int, which brace initialization rejects at compile time
  2. 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
  3. C.Use after free — writing or reading past the bounds of an array, corrupting adjacent memory and yielding undefined and often exploitable results
  4. D.Use after free — accessing memory through a pointer after the underlying allocation has been released, a common source of crashes and security flaws
Reveal the answer + AI explanation — free account

Free to start

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.

Practice Undefined Behavior and Pitfalls free