Weird variables

Aug 30, 2016 at 3:43am
I made this simple code and ran it. It gave me some weird number like 1699706. What does this number mean?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
float B,K,S,A,I;
S=StrToInt(LabeledEdit1->Text);
A=StrToInt(LabeledEdit2->Text);
B=StrToInt(LabeledEdit3->Text);
while(S>0)
{
S=S+A;
S=S-B;
K=B/100*3;
B=B+K;
I++;
}
LabeledEdit4->Text=IntToStr(I);
}
//--------------------------------------------------------------------------- 
Last edited on Aug 30, 2016 at 3:44am
Aug 30, 2016 at 3:59am
It's meaningless because your code doesn't initialize I or K.
Aug 30, 2016 at 4:07am
Thanks A LOT to you, but I want to know why this happened?
Aug 30, 2016 at 7:07am
I mean what happens in computer when it meets this line?
Aug 30, 2016 at 8:11am
Any variables you don't initialize have an undefined value. Generally, they contain whatever garbage happened to be at that memory position.
Aug 31, 2016 at 6:00am
I know what happened. I met this while debugging another program. If you don't initialize a variable, it's value is the place in the memory. It is 1935234 or something.
Aug 31, 2016 at 6:21am
I REALLY, REALLY do now.
Topic archived. No new replies allowed.