Skip to content

Variables in C Programming Language in Sinhala- Lesson 07

Variable එකක් භාවිතා කරන්නේ memory location එකකට name එකක් විදියට. එය දත්ත ගබඩා කිරීමටයි යොදාගනු ලබන්නේ. එම memory location එකට ලබාදෙනු ලබන අගය variable එක හරහා program එක තුලදී වෙනස් කිරීමට සහ නැවත නැවත භාවිතා කිරීමට පුළුවන්. Variable එක තමයි memory location නිරුපනය කරන සංකේතය.


මේක තමයි Variable එකක් සකස් කිරිමට (variable declaration) පොදුවේ භාවිතා කරන Syntax එක.

datatype variablename;


මේ තියෙන්නේ අපි කලින් lesson එකේදී කතා කරපු datatypes යොදාගෙන variable declare කරලා තියෙන විදිය.

int a;  
float b;  
char c;  

මේ a,b,c කියන්නේ variables මේවට අපිට කැමැති නමක් දෙන්න පුළුවන් නීති කිහිපයකට යටත්ව. එතකොට int,float,char කියන්නේ අපි කලින් පාඩමේ කතා කරපු data types.

මේ variables වලට අගයන් ඔයාට පසුව ආදේශ කරගන්න පුළුවන් (variable initialize). එහෙම නැත්නම් variable declaration එකේදිම ඔයාට ඒ variable initialize කරගන්නත් පුළුවන් මේ ආකාරයට.

int a=10, b=20; //declaring 2 variable of integer type
float f=20.8;  
char c='A';  


RULES FOR NAMING C VARIABLE:

  1. Variable පටන්ගතයුත්තේ letter එකකින් හෝ underscore(_) එකකින්.
  2. Variables are case sensitive (ඒ කියන්නේ int A සහ int a කියන්නේ variable 2ක්.)
  3. Variable name එකට numbers ඇතුලත් කරන්න පුළුවන්.
  4. Symbols වලින් use කරන්න පුළුවන් underscore (_) විතරයි.
  5. අලුතින් හදන variable එකකට ඊට කලින් හදපු variable name එකක් හෝ keyword එකක් name එක විදියට යොදාගන්න බැහැ.


Valid variable names:

int a;  
int _ab;
int a30;  


Invalid variable names:

int 2;
int a b;
int long;
Tagged:
Sign In or Register to comment.