Created
February 16, 2016 04:19
-
-
Save kwatch/c9a43965182e44bc32ac to your computer and use it in GitHub Desktop.
Local variable is not initialized in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| int fn() { | |
| int x; | |
| return x; // returns uninitialized local variable | |
| } | |
| int main(int argc, char*args[]) { | |
| //std::cout << "Hello\n"; | |
| std::cout << fn() << "\n"; | |
| std::cout << fn() << "\n"; | |
| } | |
| /**** | |
| $ g++ ex1.cpp && ./a.out | |
| 0 | |
| 32767 <-- !!!!!!! | |
| $ g++ --version | |
| Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 | |
| Apple LLVM version 7.0.2 (clang-700.1.81) | |
| Target: x86_64-apple-darwin15.3.0 | |
| Thread model: posix | |
| ****/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment