GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 445 of 453    Print  
Garbage Value
In C if a variable is not assigned a value then why does it take garbage value?



  
Total Answers and Comments: 2 Last Update: March 05, 2009     Asked by: ajayvyas 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: mihir_void
 
This happens only in case of local varibales. As memory for local variables are allocated on stack and while allocating the memory the runtime system does not clear the memory before allocating it to the variable unlike in case of allocating memory in heap for global and static variables. Hence the default value of local varibles beomes the content of its memory on stack while that of constant and static variables is 0.

Above answer was rated as good by the following members:
zivora
January 21, 2009 17:44:45   #1  
nemuns Member Since: January 2009   Contribution: 3    

RE: Garbage Value

When the variable is assigned an address it takes the data at that particular address which we see as a junk or garbage value.


 
Is this answer useful? Yes | No
March 05, 2009 15:07:46   #2  
mihir_void Member Since: March 2009   Contribution: 3    

RE: Garbage Value
This happens only in case of local varibales. As memory for local variables are allocated on stack and while allocating the memory the runtime system does not clear the memory before allocating it to the variable unlike in case of allocating memory in heap for global and static variables. Hence the default value of local varibles beomes the content of its memory on stack while that of constant and static variables is 0.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    

 Related Questions

A) Runtime error. Access violationB) Compile error. Illegal syntaxC) None of the aboveD) Runtime errorExplanation: printf( ) prints address/garbage of i, scanf() dont have & sign, so scans address for 
Latest Answer : The printf will give some junk value (address) and scanf will wait for the input from user. once u enter a value u'll get Bus error(coredump). ...

What is the output of the following program?#define SQR(x) (x*x)main(){     int a,b=3;     a= SQR(b+2);     printf("%d",a);}
A) 25B) 11C) ErrorD) Garbage Value 

What would be the output of the following program? main() { int y=128; const int x=y; printf("%d",x); }
A) 128B) Garbage valueC) ErrorD) 0 

What would be the output of the following program? main() { const int x=5; int *ptrx; ptrx=&x; *ptrx=10; printf("%d",x); }
A) 5B) 10C) ErrorD) Garbage Value 

Printf ("%d" ,printf {"tim") ); 1. results in a syntax error 2. outputs tim 3 3. outputs garbage 4. prints tim and terminates abruptly
Read Answers (10) | Asked by : Rujul

In C if a variable is not assigned a value then why does it take garbage value? 
Latest Answer : This happens only in case of local varibales. As memory for local variables are allocated on stack and while allocating the memory the runtime system does not clear the memory before allocating it to the variable unlike in case of allocating memory in ...
Read Answers (2) | Asked by : ajayvyas


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.  By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.  IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

History of Neuro Linguistic Programming (NLP)

History of Neuro linguistic programming Neuro Linguistic Programming NLP is a system co founded by John Grinder and Richard Bandler for bringing about personal development in any individual by interpreting and translating the human perception experience beliefs and language It was developed in early
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape