You got lucky. Returning from the function doesn’t immediately wipe the stack frame you just exited.
BTW, how did you confirm that you got a 6 back? The expression std::cout << &i ...
prints the address of i
, not its value.
More Related Contents:
- Error while using if statements [closed]
- How to get values and save them to use later on Arduino?
- Why does C++ code for testing the Collatz conjecture run faster than hand-written assembly?
- Why can’t I make a vector of references?
- Why can’t C++ be parsed with a LR(1) parser?
- Generating random integer from a range
- How can I clear console
- Determine the line of code that causes a segmentation fault?
- Should I use std::function or a function pointer in C++?
- When to use std::size_t?
- How to create a static library with g++?
- Stack Memory vs Heap Memory [duplicate]
- Variable assignment in an “if” condition
- Scope of variables in if statements
- Accessing certain pixel RGB value in openCV
- Simple object detection using OpenCV and machine learning
- A proper way to create a matrix in c++
- Why are string literals const?
- C++: Converting Hexadecimal to Decimal
- C++ new operator thread safety in linux and gcc 4
- C++ templates specialization syntax
- Why are some functions in not in the std namespace?
- How to read entire stream into a std::string?
- What does ‘const static’ mean in C and C++?
- What is the performance cost of having a virtual method in a C++ class?
- Why is iterating though `std::vector` faster than iterating though `std::array`?
- Returning to beginning of file after getline
- std::lexical_cast – is there such a thing?
- How to test whether class B is derived from template family of classes
- What’s the difference between istringstream, ostringstream and stringstream? / Why not use stringstream in every case?