.... အားလံုးအတြက္ မဟုတ္ခဲ့ရင္ေတာင္ တစ္စံုတစ္ရာ တစ္စံုတစ္ေယာက္အတြက္ ေႏြးေထြးတဲ့ ေကာင္းကင္ငယ္ေလး ျဖစ္ပါရေစ ....

Friday, December 24, 2010

Data type & Variables & String

Data type
   Date type ဆိုတာကေတာ့ ကၽြန္ေတာ္တို ပရိုဂရမ္မွာသက္မွတ္ေပးထားတဲ့ variables ရဲ format နဲ႔ date ပဲျဖစ္ပါတယ္
ဥပမာ ထားပါေတာ့
Int x;
Char y ;
Double  z;
 ဒီေနမွာဟာ x,y,z ဆိုတာ variable name ျဖစ္တယ္ဆိုတာ အေပၚမွာေျပာျပခဲျပီးျဖစ္ပါတယ္ .. သူအေရွက int,char,double ဆိုတာကေတာ့ date type ေတြပါပဲ .. သက္ဆိုင္ရာ type ေတြမွာ သက္ဆိုင္ရာ တန္ဖိုးသက္မွတ္ခ်က္ေတြ ရွိပါတယ္ ..မိမိေရးသားတဲ့ပရိုဂရမ္ေပၚမူတည္ျပီး type ေတြကို ခြဲျခားသံုးျပဳရပါ့မယ္ .. ထားပါေတာ့ ကၽြန္ေတာ္တိုက ၂ နဲ ၃ ကိုေပါင္းမယ္ဆိုရင္ ကိန္းျပည့္ပဲရမွာျဖစ္တဲ့အတြက္ int date type ကိုသံုးျပဳလိုရပါတယ္ … ဒါေပမယ့္ ၂ ကို ၃ နဲ စားခဲ့မယ္ဆိုရင္ေတာ့ ဒသမကိန္းရမွာျဖစ္တဲ့အတြက္ ကိန္းျပည့္ int ကိုသံုးလိုမရေတာ့ပါဘူး .. ဒသမအတြက္ သက္မွခ်က္ျဖစ္တဲ့ float Or double ကိုသံုးရမွာပါ .. ကဲအဲဒီအတြက္ ဘယ္ေကာင္မွာ ဘယ္ေလာက္တန္ဖိုရွိတယ္ဆိုတာ ေအာက္မွာေဖာ္ျပေပးလုိက္ပါတယ္ ေအာ္ကြန္ပ်ဴတာက နားလည္လက္ခံတဲ့ တန္ဖိုးဆိုတာက အမွန္ေတာ့ byte ေတြပါ ဒီကေနမွာတစ္ဆင့္ range ေတြတြက္ျပီး ကၽြန္ေတာ္တိုက နားလည္လိုက္တာပါ ..

Type Name
Bytes
Other Names
Range of Values
int
4
signed
–2,147,483,648 to 2,147,483,647
unsigned int
4
unsigned
0 to 4,294,967,295
__int8
1
char
–128 to 127
unsigned __int8
1
unsigned char
0 to 255
__int16
2
short, short int, signed short int
–32,768 to 32,767
unsigned __int16
2
unsigned short, unsigned short int
0 to 65,535
__int32
4
signed, signed int, int
–2,147,483,648 to 2,147,483,647
unsigned __int32
4
unsigned, unsigned int
0 to 4,294,967,295
__int64
8
long long, signed long long
–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned __int64
8
unsigned long long
0 to 18,446,744,073,709,551,615
bool
1
none
false or true
char
1
none
–128 to 127 by default
0 to 255 when compiled with /J
signed char
1
none
–128 to 127
unsigned char
1
none
0 to 255
short
2
short int, signed short int
–32,768 to 32,767
unsigned short
2
unsigned short int
0 to 65,535
long
4
long int, signed long int
–2,147,483,648 to 2,147,483,647
unsigned long
4
unsigned long int
0 to 4,294,967,295
long long
8
none (but equivalent to __int64)
–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long long
8
none (but equivalent to unsigned __int64)
0 to 18,446,744,073,709,551,615
enum
varies
none
See Remarks.
float
4
none
3.4E +/- 38 (7 digits)
double
8
none
1.7E +/- 308 (15 digits)
long double
same as double
none
same as double
wchar_t
2
__wchar_t
0 to 65,535

Declaration of  Variables

Variables ေတြကို ေၾကျငာေတာ့မယ္ဆိုရင္ အေပၚမွာျပထားခဲ့သလိုပါပဲ မိမိေပးလိုတဲ့နာမည္နဲ type ကိုတြဲျပီးေဖာ္ျပေပးရပါမယ္

int a;
int b;
int c;
char x;
char y;
double p;

ဒီေနရာမွာ type တူတာေတြကိုေပါင္းျပၤီးေဖာ္ျပလိုရပါတယ္
int a,b,c
char x,y,z;
double p;
အတူတူပါပဲ ..တန္ဖိုးကို ဒီလိုမ်ိဳးလည္းေျပာင္းလိုရပါေသးတယ္.

type identifier = initial_value ; type identifier (initial_value) ;

int a = 0;
int a(0);

ေအာက္မွာနမုနာၾကည့္ပါ

// initialization of variables
 #include <iostream>
using namespace std;
 int main ()
{
  int a=5;               // initial value = 5
  int b(2);              // initial value = 2
  int result;            // initial value undetermined
   a = a + 3;
  result = a - b;
  cout << result;
   return 0;
}

ဒီေနရာမွာ Globle နဲ႔ Local ဆိုတာကိုေျပာျပခ်င္ပါတယ္ ..

Main() အတြင္းမွာရွိတဲ့ ေၾကျငာခ်က္ေတြ အားလံုးဟာ Local ေတြပါပဲ သူအတြက္ ပရိုဂရမ္ရဲ အဓိက main () function တစ္ဥိးထဲကပဲ ပိုင္ဆိုင္တာပါ .. အျခား function() ေတြအတြက္က သီးသန္ လိုက္ေၾကျငာေပးရပါတယ္ အကယ္လို main() function ကေကာ အျခား function() ေတြကပါ ဒီနာမည္ကို အတူတူသံုးျခင္တယ္ဆို Globles ဆိုတာနဲေၾကျငာ ေပးရပါတယ္ ေအာက္ကပံုကိုၾကည့္ရင္ နားလည္သြားလိမ့္မယ္ထင္ပါတယ္

  
Introduction to String
          String ဆိုတာ ပရိုဂရမ္မွာ ေရးသမွ်စာသားအစုအေ၀းေတြ ကိုဆိုလိုတာပါ သူကိုသံုးေတာ့မယ္ဆို Header file : <string> ကိုေခၚယုူသံုးျပဳရမွာျဖစ္သလို “ ” ဆိုတဲ့သေကၤတၾကားထဲမွာပဲ စာသားေတြကို ေရးရမွာပါ.

string mystring = "This is a string";
string mystring ("This is a string");  ဒီ ၂ ခု အတူတူပါပဲ .. ေအာက္မွာနမူနာၾကည့္ပါ
  
// my first string
#include <iostream>
#include <string>
using namespace std;
 int main ()
{
  string mystring;
  mystring = "This is the initial string content";
  cout << mystring << endl;
  mystring = "This is a different string content";
  cout << mystring << endl;
  return 0;
}

0 မွတ္ခ်က္: