Jump to content

Float variable is keep returning wrong huge value. Please help

Featured Replies

When I am entering vaules to my float variables some of them are returning wrong huge numers.

For example I entered 0 and it returned 916455424.

 

Please can anybody tell me the reason or solution?

If you would have f.e. array overflow on stack or structure, you would be reading wrong values in data prior, or after field that has overflow.

 

f.e.

 

struct X

{

float data1;

char data2[ 10 ];

float data3;

};

 

X x;

x.data2[ -1 ] = 123; // array entry at index -1 is in reality data1

x.data2[ 10 ] = 456; // array entry at index 10 is in reality data3


It happens more often than you think- typically index to array is dynamic, not static like in example above. So there might happen some bug causing reading/writing from negative index, and reading/writing wrong value from/to wrong place.

And if it is array data in C, then bobes may be accidentally printing the address of a variable instead of the content.

 

Or it could be an uninitialised variable.

 

Or a local variable being accessed out of scope so it has been overwritten.

 

Or ...

Or it could be an uninitialised variable.

that usually ends up with an error or null.

that usually ends up with an error or null.

Unless he OP usually uses a different programming language than you usually do. Out of curiousity: In which programming languages does no initializing a basic float value end up with an error or null?

Unless he OP usually uses a different programming language than you usually do. Out of curiousity: In which programming languages does no initializing a basic float value end up with an error or null?

I think a majority of languages do. You have to initialize the variable in the first place in order to use it, I would think. :huh: And the language the OP is using is either C or C++. I could be wrong.

 

 

int t;

int t = 0;

I could be interpreting the statement wrong, though.

Edited by Unity+

I guess we will never know ...

Unless the OP comes back, I think this thread is dead.

  • 2 months later...

Maybe you are using the same variable again and again. For Exmaple : sum=sum+i; Now here if sum is not declared as int sum=0; then junk value of sum will be printed instead of the actual value. Try print an integer variable without assigning any value to it ; you will get some junk value printed. I guess this maybe your problem.

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.