name and type of variables in C + + programming

Variables can be described as a bag that can hold anything. In a program that asks the user input, then inputannya be accommodated into the pockets of the named variables. And this bag can also be accessed by any other program statements. The following are various types of variables.

Nama Tipe

Range

Type

Shortint

-128 s/d 127

Integer

Byte

0 s/d 255

Integer

Integer

-32768 s/d 32767

Integer

Word

0 s/d 65535

Integer

Longint

-2146473648 s/d 2146473647

Integer

Real

2.9 e-39 s/d 1.7 e37

Pecahan

String

s/d 255 huruf

Non numeric

Char

1 huruf saja

Non numeric



Type the above variables are the type most commonly used variables. For the type of fractions, there are still types like single, double, extended, etc.. Please learn your own to the help available (Ctrl + F1). Next is a way of declaring variables. Variables declared in the block var. example:
Var
  umur : byte;
  nama : string;
To give a value to a variable, the command input statement:
:= ;

Var
  umur : byte;
  sekolah : string;
begin
  umur := 20;
  sekolah := 'iSTTS';
  writeln('Umurku ',umur,' tahun');
  writeln('Aku bersekolah di ',sekolah);
end.

Run and see the results! So what if we want to ask for input from the user. Use the command read or readln. Example program:

Var
  umur : byte;
  sekolah : string;
begin
  write('Umur saya berapa? '); readln(umur);
  write('Sekolah saya di mana?'); readln(sekolah);
  writeln('Umurku ',umur,' tahun');
  writeln('Aku bersekolah di ',sekolah');
  readln;
end.

Run! If you enter the input and press enter. Then, since the most recent statement asking readln program. That means we must press the enter key to return to the editor.

0 comments:

Post a Comment