Aug 30, 2016 at 3:43am UTC
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 UTC
Aug 30, 2016 at 3:59am UTC
It's meaningless because your code doesn't initialize I or K.
Aug 30, 2016 at 4:07am UTC
Thanks A LOT to you, but I want to know why this happened?
Aug 30, 2016 at 7:07am UTC
I mean what happens in computer when it meets this line?
Aug 30, 2016 at 8:11am UTC
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 UTC
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.