answersLogoWhite

0


Best Answer

For static and global variables it is 0; automatic variables are not initialized by default.

in the c language there is no default value for non static local variables. The variable holds whatever was in memory before it became a variable. It's best to always initialize a non static local variable before using it in the c language (or at least before comparing it to something else). Also It's best to assume that there is no default value because this varies from language to language, and hardware to hardware.

Cheers!

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

The default value is whatever happens to be present in the memory location at the point of allocation. If allocated on the stack, it will generally be zero. On the heap it could be anything, and must be initialised before being used.

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

A default argument is a formal argument to which we have assigned a default value. If we do not explicitly supply a value for that argument, the default value will be chosen instead.

void f (int=0);

In the above example, the function f() expects an argument of type int but if we call the function without supplying a value for that argument, then the value 0 will be used by default:

f (42); // ok, argument supplied

f (); // ok, same as invoking f (0)

When a function has two or more arguments and we assign a default to any one of them, we must also assign default values to any and all of the arguments that follow it.

void f1 (int, double=0.0); // ok -- trailing argument has a default value

void f2 (int=0, double=0.0); // ok -- all arguments have default values

void f3 (int=0, double); // error -- second argument requires a default

If we cannot provide a suitable default value for the second argument in f3(), then we must swap the order of the arguments instead:

void f3 (double, int=0); // ok

Note that when we define a function that has already been declared with default values, we do not include those default values in the definition:

void f3 (double d, int i=0) { // error -- default value already given in declaration

// ...

}

For documentation purposes we can use a C-style comment to show default values in function definitions that have previously been declared:

void f3 (double d, int i /*=0*/) { // ok

// ...

}

However, it's best to avoid this as it can lead to inconsistencies if we subsequently change the default in the declaration but forget to also update the definition. The declaration alone provides all the documentation we need, repeating it in the definition only increases the maintenance burden.

When we combine default values with function overloading, we may incur an ambiguity:

void f4 ();

void f4 (int=0);

f4 (); // ambiguous: f4 () or f4 (0)?

Default values are most useful when defining constructor overloads as they allow us to combine several different constructors into one.

class date {

private:

int dd, mm, yyyy;

public:

date (int d=1, int m=1, int y=2001) dd {d}, mm {m}, yyyy {y} {}

// ...

};

date (); // invoke date (1, 1, 2001)

date (2); // invoke date (2, 1, 2001)

date (3, 3); // invoke date (3, 3, 2001)

date (4, 2, 2018); // invoke date (4, 2, 2018)

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the default value of integer in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

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 default value of formal arguments?

In C, there is no default value for formal parameters. In C++, there can be, but the value is whatever you declare in the function declaration.


What data-type is a numeric value entered into a text box treated as by default an integer B String C Variant D None of the above?

integerstring


Which is the default parameter passing technique in c plus plus language?

The default is to pass by value.


What are the different parameter passing methods used by c plus plus?

Pass by value, constant value, reference and constant reference. Pass by value is the default in C++ (pass by reference is the default in Java).


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 the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


What is the last value of case in switch in c?

I guess you mean 'default'


What is the default data type?

integer


What parameter to a function is one for which an automatic value is supplied if do not explicitly use one in C programming?

You are referring to default arguments. However, C does not support default arguments. That's a C++ feature.


Can an integer data type in c plus plus stores character value?

no


How do you get the absolute value of positive integer?

The absoluate value of a positive integer is the integer itself.The absoluate value of a positive integer is the integer itself.The absoluate value of a positive integer is the integer itself.The absoluate value of a positive integer is the integer itself.