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

Is the value of x just some random bits?

2007-03-29 04:18:02 · 4 answers · asked by therealjackbauer 1 in Computers & Internet Programming & Design

4 answers

The value you get is what ever was in that part of memory before. So yes this is usually a random piece of information.
But if you define a string and then display the data, remembering that there will be some non-printable characters, you may find that you always get the same information.
This is all dependent on the compiler and the computer on which the program is running.

2007-03-29 04:28:07 · answer #1 · answered by AnalProgrammer 7 · 0 0

A variable in C that has not been initialized can be in one of two states depending on the version of C you are using:

In one version, it is assigned a memory address that is cleared of any previous info. In this case, the variable is "null".

In other versions, the memory address may NOT be cleaned out, and in that case the variable is "undefined".

Most of the C programming languages I've used were of the latter variety, and you can get strange results if you try to use the undefined value accidentally.

2007-03-29 11:26:19 · answer #2 · answered by SteveN 7 · 1 0

Yes, it picks a memory location to store the variable in, so the variable will assume the value of whatever data was already in that memory location.

2007-03-29 11:25:06 · answer #3 · answered by undercoloteal 3 · 1 0

Yes, usually to a random location in heap memory.

2007-03-29 13:07:40 · answer #4 · answered by cbr900rrderrick 1 · 0 1

fedest.com, questions and answers