Linked Questions
85 questions linked to/from What should happen when printing an uninitialized variable?
12 votes
4 answers
5k views
What happens when I print an uninitialized variable in C++? [duplicate]
Why does this print 32767 (or some other random number)? What is std::cout printing? Why is it not NULL (or 0)? int main() { int a; std::cout << a; }
3 votes
7 answers
2k views
Assigning pointer to uninitialized variable changes it value? [duplicate]
I'm playing with c++ in VisualStudio2010 Please explain why IT happens: int a, b; int *p, *q; cout << a << " " << b; prints out "0 0". Well it's understandable, uninitialized ...
0 votes
5 answers
3k views
What happens to uninitialized variables in C/C++? [duplicate]
From "C++ Primer" by Lippman, When we define a variable, we should give it an initial value unless we are certain that the initial value will be overwritten before the variable is used for ...
-3 votes
2 answers
11k views
C/C++ the result of the uninitialized array [duplicate]
It might be a boring question! thanks! Here's the code: #include <iostream> #include <cstring> using namespace std; int main() { int a[5] = {0}; int b[5]; cout &...
5 votes
2 answers
5k views
Variable has value without being assigned C++ [duplicate]
#include <iostream> #include <string> using namespace std; int count_number_place(int number) { int number_placement; while (number >= 1) { number_placement++; ...
2 votes
3 answers
3k views
What happens to uninitialized variables? C++ [duplicate]
int main() { int a; cout << a; return 0; } I am wondering why the value 0 is being output. I thought if a variable is uninitialized, it would output a garbage value. However, I ...
2 votes
4 answers
3k views
hourglass in c++, hackerrank [duplicate]
I was trying to solve Hourglass problem in C++ on HackerRank. The task is following: Given a 6x6 2D Array, A: 1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 We define an ...
0 votes
1 answer
581 views
Can garbage value be expected in c++? [duplicate]
My teacher told me that he is studying about compiler and he found out that garbage value in c++ can be expected or calculated with a formula like this = Range of that datatype - size of datatype = ...
0 votes
3 answers
327 views
C++ initializes value for variable even though I left it empty, why does this happen? [duplicate]
For some reason, the value of final_sum is 16 but I didn't initialize a value for that variable, why's that? Isn't supposed to start with 0? #include <iostream> #include <iomanip> #include ...
0 votes
3 answers
455 views
What determines the initial value of C++ variables [duplicate]
If I don't initialize a C++ variable, I find that it automatically gives it 0 on some android phones, but not on others, and zero on all IOS phones. So what determines whether you give it 0, is it the ...
0 votes
1 answer
620 views
When I run the program in DevC++ 5.11 TDM-GCC 4.9.2 doesn't work how I expect, but in an online compiler it just works [duplicate]
I'm a newbie in the programming world, and i've decided to start with C++ code a few days ago as my first programming language. I just started to read an online course which i'm guiding on (and aply ...
0 votes
2 answers
509 views
Primitive types in C++ vs in C [duplicate]
In C++, having primitive type (int, double, char, ...) not-defined so undefined behaviour. There is no default value for primitive types, because they have no constructor. But the compiler is ...
0 votes
1 answer
431 views
Uninitialized pointer, points to zero [duplicate]
#include <iostream> int main() { int* pt; std::cout << pt << std::endl; if(pt) std::cout << "true" << std::endl; else std::cout << "...
0 votes
1 answer
198 views
Why is C++ implicitly converting 0.0 to some extremly small 'random' value? [duplicate]
I'm trying to compare two class objects, which has both been initialized with 0.0, but for some reason C++ decides to convert the 0.0 to some extremly small value instead of keeping the 0.0, which ...
0 votes
2 answers
610 views
C++ error: The right operand of '*' is a garbage value [duplicate]
I finally completed my code and when I submit it I received a couple errors. It keeps telling me 73:15 Incorrect spacing around >=. 73:31 Incorrect spacing around <=. for this line, I've ...