answersLogoWhite

0

None. If you don't initialize them, you find garbage in them.

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

What is the default initial value for all numeric types?

If they are instance variables the default initial value is 0. If they are method local variables, they are null and must be initialized to some value before they are used


Are C variables initialized to 0 by default?

Only global/static variables are, local variables aren't.


Do variables that are declared but not initialised contain garbage values?

It depends on the language. In C and C++, all static variables are zero-initialised at runtime but local variables are not, thus an uninitialised local variable will hold whatever value happens to reside at the memory allocated to the variable at runtime. However, the C/C++ compiler can be configured to warn against using an uninitialised variable. In object oriented languages like Java there's no such thing as an uninitialised variable. This is because all Java variables are objects so we must pass the initial value to the object's constructor unless the object has default constructor. Attempting to default construct an object that has no default constructor is a syntax error.


What is static variable in the class in cpp?

Static member variables of a class are variables that are local to the class within which they are declared. That is, each instance of the class (each object) shares the same common member variable. Changing that variable's value in one instance will change it for all instances. Contrast with a non-static member variable where each instance of the class has its own independent variable, scoped to the object itself (not the class of object).


What is the default value of integer in java?

According to the JLS, the default value of an int is 0. The default value of an object of type Integer is null. Of course, this applies only to class members fields, as local method-level fields must be explicitly assigned a value before use.

Related Questions

What is the default initial value for all numeric types?

If they are instance variables the default initial value is 0. If they are method local variables, they are null and must be initialized to some value before they are used


Are C variables initialized to 0 by default?

Only global/static variables are, local variables aren't.


When posting variables if you do not value the variable then you want to display the variable value. What is going on Explain?

I believe you are referring to uninitialised variables, although it's hard to tell from the wording of the question. If you attempt to print the value of an uninitialised variable, the behaviour is undefined. Typically, when a variable is uninitialised, the memory to which the variable is allocated will be left unchanged; it will hold whatever value happened to exist there at the point the variable was instantiated. However, only local variables (allocated on the stack) and dynamic variables (allocated on the heap) are uninitialised by default. Static variables are zero-initialised by default and object variables are always initialised according to whichever class constructor was invoked at the point of instantiation. Most compilers will detect attempts to use uninitialised local variables and will emit warnings to that effect during compilation.


Do variables that are declared but not initialised contain garbage values?

It depends on the language. In C and C++, all static variables are zero-initialised at runtime but local variables are not, thus an uninitialised local variable will hold whatever value happens to reside at the memory allocated to the variable at runtime. However, the C/C++ compiler can be configured to warn against using an uninitialised variable. In object oriented languages like Java there's no such thing as an uninitialised variable. This is because all Java variables are objects so we must pass the initial value to the object's constructor unless the object has default constructor. Attempting to default construct an object that has no default constructor is a syntax error.


What is the default value of int in c?

I'm not sure. I have written C programs in which the default value was what ever happened to be in the variable's memory location when the space was allocated. So it could be 0. Or it could be anything. That is why it is always important to initialize variables when using C. I don't know if this is true with modern C compilers. No default value for automatic variables, 0 for others.


What is static variable in the class in cpp?

Static member variables of a class are variables that are local to the class within which they are declared. That is, each instance of the class (each object) shares the same common member variable. Changing that variable's value in one instance will change it for all instances. Contrast with a non-static member variable where each instance of the class has its own independent variable, scoped to the object itself (not the class of object).


What is the default value of integer in java?

According to the JLS, the default value of an int is 0. The default value of an object of type Integer is null. Of course, this applies only to class members fields, as local method-level fields must be explicitly assigned a value before use.


What is the initial value of a numeric variable?

When we talk about instance variables, the default initial value for a numeric variable is always '0'. Any other variable in your code must be initialized before you can use it. public class MyClass{ public int x; // 0 by default public float y: // 0 by default public MyClass{ int z; z++; // Error 'z' don't have a default value } }


What is the initial value of (-1-17) and (-3-15)?

When we talk about instance variables, the default initial value for a numeric variable is always '0'. Any other variable in your code must be initialized before you can use it. public class MyClass{ public int x; // 0 by default public float y: // 0 by default public MyClass{ int z; z++; // Error 'z' don't have a default value } }


What is automatic storage class specifiers?

Automatic storage is the default storage class for all non-static local variables including formal arguments. All automatic variables are allocated on the call stack and are automatically released when they fall from scope.


What is default values of different primitive data types?

in integral data types default value=0 in decimal type default value is 0.0 in boolean default value is fa


What are continuous and discrete variables?

the value of variables is determined by the equation, discrete variables have absolute single value while the continuos have a range value