473,486 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

What is garbage value in c/c++??

5 New Member
wht is garbage value?? how it generates and why it generates?? why default value is not null in c/c++
Jan 25 '11 #1
3 10013
weaknessforcats
9,208 Recognized Expert Moderator Expert
A garbage value is a vaue that is not correct for your variable. Like a variable named Month with a value of 32 when there are only 12 months.
Jan 25 '11 #2
Oralloy
988 Recognized Expert Contributor
Anchal,

weaknessforcats is an absolute C++ Guru, and a darned fine teacher, too; so read carefully everything she writes.

If you want a "garbage" value like "Empty" or "Nothing" as in VBA, there is no such thing in C++. There is always a value in a C++ variable. That value will be used in all subsequent calculations using that variable, until the variable is overwritten.

If you corrupt a variable (say by overrunning an array that's on the stack), then the corrupt value will be used quietly in subsequent calculations. The lesson being that your functions should check all arguments when called.

In general, NULL is to pointers, what "Nothing" is to objects in VBA, however there is no equivalent of "Empty" or the "Null" value for variants.

Cheers!
Oralloy
Jan 25 '11 #3
donbock
2,426 Recognized Expert Top Contributor
The following discussion is for C. Your C++ mileage may vary ...

Static variables are automatically initialized to 0 unless you specify some other initializer value.

Automatic variables are not automatically initialized unless you have an explicit initializer. The value of a no-initializer automatic variable is unknown (that is, garbage) until an executable statement puts a value in it.

Heap variables do not support initializers. The value of a heap variable is unknown (that is, garbage) until an executable statement puts a value in it (unless you used calloc to allocate the heap variable).
Jan 26 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1665
by: arunvnk | last post by:
int main() { product g; product t; fstream k; k.open("stock.txt",ios::app|ios::in); int op=0; static int count=0; //k.open("stock.txt",ios::app,ios::in); while(op<4)
2
1595
by: andrew browning | last post by:
this program is a binary tree using nodes. it should do an in-order print, which it does. however, it inserts a garbage value at the end of the print. ex: cin >> 1 2 3 4 5 prints 1 2 3 4 5...
1
1482
by: lokesh yadav | last post by:
hi i need explanation why stack contains garbage while we refer to stack default is any method to clean the stack my program exit so that my stack should contain zero as default...
23
3626
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
4
3690
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
1
1244
by: jayman9782 | last post by:
I'm working with ASP.NET 1.1 and I am attempting to compare the value of a textbox on the pages onunload event. The screen that is open is a pop-up screen that can be opened from links on two...
158
7681
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
8
7345
by: Aftabpasha | last post by:
I have seen a simple program for handling Link List operations. The following is the part of the code that contains the problem. The code is modified but contains all necessary information regarding...
1
1658
by: MANISH AGRAWAL | last post by:
/*programming for partition the elements of the array so that all the even numbers move to one side and odd numbers to the other side of the array.*/ #include<stdio.h> int main() { int...
1
1631
by: Eswarranjani | last post by:
what is $$ value..? what it returns in shell scripts..?
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.