English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

This is one of those questions that depend on the compiler you are using.
Generally speaking the default value will be unpredictable but could be what ever was in memory before being allocated.
That is to say you should always give all your variables an initial value.

2007-07-10 02:59:48 · answer #1 · answered by AnalProgrammer 7 · 1 1

Some compilers have an option to automatically set data types to a default value of null or zero, dependent upon the data type. However, according to the ANSI C standard data types should not have a default value. As such they will contain whatever unpredictable value is stored at the referenced memory location.

2007-07-10 10:02:15 · answer #2 · answered by Rob 3 · 0 1

There're no default values in C.
You just get what it was in the allocated memory: any junk can be there, so it is not possible to predict the value of uninitialized variable in C.

Some runtimes clear the memory before allocating, so on some systems you can get all zeros by default. However, that's not guaranteed. You program should not rely on this.

2007-07-10 10:00:30 · answer #3 · answered by wschmerz 5 · 0 1

fedest.com, questions and answers