What is the range of junk values in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is the range of junk values in C++?

7th Aug 2018, 8:39 AM
Thejus Joseph
11 Answers
+ 4
Since any possible value can be left behind, the range is the same as however you declare your new variable. unsigned int will be 0 to 4294967295, while a signed int in the same location will be -2147483648 to 2147483647.
7th Aug 2018, 9:59 AM
John Wells
John Wells - avatar
+ 5
The range of garbage values are directly specified by the data type by which we declare variables, array and in general any kind of identity that needs to store and retrieve the data to/from memory. We can prove it by doing a couple of quick examples. Example 1: Examining the garbage values of an uninitialized char array. char cc[10]; for (auto &i : cc) cout << i << endl; Possible output: 40 1 0 0 116 38 0 64 144 42 Here, the range of garbage values are min = numeric_limits<char>:: min(); // mostly 0 max = numeric_limits<char>::max(); // mostly 255 Example 2: Examining the garbage values of an uninitialized int array. int nn[5]; for (auto &i : nn) cout << i << endl; Possible output: 4096 34 -2356 1074001547 0 Here, the garbage values are greater than before since we've used integer type and thus the range would be as min = numeric_limits<int>::min(); // usually -2147483648 max = numeric_limits<int>::max(); // usually 2147483647
7th Aug 2018, 12:43 PM
Babak
Babak - avatar
+ 2
If you're talking about data type ranges then you can see on the link below. int size and range varies between systems and compilers, if you mean 16bit int, then its range is between -32768 to 32767. Yet again, data type ranges has nothing to do with garbage values: (EDIT) Recent posts has proven that my understanding was incomplete, and that data types actually defines what range of value could possibly be stored on uninitialized variables. Always something new to learn. Thanks. https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx
7th Aug 2018, 9:26 AM
Ipang
+ 1
yup
7th Aug 2018, 9:02 AM
Thejus Joseph
+ 1
I don't recall there is a range for garbage value, that's why I ask you, if you don't want your variable to contain garbage value then get into habit of initializing them before using them. Anyways, there is an interesting discussion about variable initialization, where it is really necessary, which types do self initialization, you may read it here: https://www.sololearn.com/Discuss/1128723/?ref=app Hth, cmiiw
7th Aug 2018, 9:11 AM
Ipang
+ 1
kay
7th Aug 2018, 9:29 AM
Thejus Joseph
+ 1
But my lecturer told that Garbage values have a range and he doesnt know it. He hs been searching its answer for a very long time...
7th Aug 2018, 9:36 AM
Thejus Joseph
0
What do you mean range of junk values? did you mean garbage value?
7th Aug 2018, 9:01 AM
Ipang
0
Ikr but I just wanted to know the range...
7th Aug 2018, 9:15 AM
Thejus Joseph
0
I still don't understand what you mean by range here, well maybe someone can come later to say something, good luck!
7th Aug 2018, 9:17 AM
Ipang
0
Range in the sense the range of values bw. 2 values i.e, for example the range of int is -32276 to 32276
7th Aug 2018, 9:19 AM
Thejus Joseph