CJCoding With Joseph
15per day
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #32

Pointer to Local Variable

mediumDynamic Memory

This code compiles with a warning but produces unpredictable output. What is the bug?

📄 Code

1#include <iostream>
2using namespace std;
3 
4int* createNumber() {
5 int value = 42;
6 return &value;
7}
8 
9int main() {
10 int* p = createNumber();
11 cout << *p << endl;
12 return 0;
13}