Garbage value in programming language

Asked By 0 points N/A Posted on -
qa-featured

 What is garbage value in a programming language?

Please list some examples that gives garbage values in turbo C++?

SHARE
Best Answer by Rodney2001
Best Answer
Best Answer
Answered By 0 points N/A #93702

Garbage value in programming language

qa-featured

A garbage is something that happens as a result of not being able to initialize a local variable/ memory that you got from Malloc. This normally happens when there is garbage value that interferes with the systems operation.

An example of a pure garbage value is this int s and int p then s=p; p is not initialized and so it becomes a garbage value.

Some computers present the same problem not being to recognize some letters and numbers so that when you click some numbers they are usually tampered with.

Another example is when  you can get only the maximum height and not the minimum height in an operation in your system. Also when it becomes difficult to run simple to figured operations in your program all this point up to garbage value C++.

Answered By 0 points N/A #93703

Garbage value in programming language

qa-featured

If you mean the values of uninitialized variables, those aren't generated. They're just whatever garbage happened to be in that memory location.

examples of garbage values in turbo c++

int *foo = new int;
std::cout << *foo << std::endl;

New returned a pointer to some address in memory. That bit of RAM has always existed; there is no way to know what was stored there before. If it was just requested from the OS, it'll likely be 0 (the OS will erase memory blocks before giving them out for security reasons). If it was previously used by your program, who knows.

Actually, the results of using an uninitialized variable are undefined. You might get back an unpredictable number, your program may crash, or worse.

Even if you know that its safe to run the above on your platform, you shouldn't rely on that giving a random value. It will appear random, but is probably actually quite a bit more predictable and controllable than you'd like. Plus, the distribution will be nowhere near uniform.

Thank you.

Related Questions