මොනවද මේ Computer Data & Variables?
පරිගණකයේ දත්ත ගබඩා කරනකොට ඒවා අපි දන්නවා ඒක ඩිජිටල් ක්රමේකට තමයි ස්ටෝර් වෙන්නේ-
මේ Variables 1ක් කියන්නේ පරිගණකයේ ram1 ඩේටා ස්ටෝ කරන ස්පේස් 1ක්- ඒක තමයි කියන්න පුලුවන් ලේසිම විදිය.මෙම Variable 1ක් සෑදු විට ram1 යම් ඉඩ කඩක් සැකසේ- අනතුරැව අපට එයට value assign කළ හැක-
data type ගොඩක් තියෙනවා- ඒ ඒ අගයන් සදහා ඒ ඒ ගැලපෙන data type ඇත-( උදා---- නිඛිල සදහා int)
අපි උදාහරණයක් බලමු
#include<stdio.h>
int main(){
int x; -------------මෙවිට රෑම් 1 ස්පේස් 1ක් සැකසේ
x=100; --------------100 ඩිජිටල් ක්රමේට සකසා ඉහත ස්පේස් 1 ස්ටෝ වේ
printf("%d\n",x); --------එම අගය ප්රින්ට් කරයි(කන්සෝල් 1හි)
return 0;
}
ඔයගොල්ලො බලයි printf("%d\n",x); ඇතුලේ තියෙන "%d\n" මේක මොකක් ද කියල- අපි ප්රින්ට් කරන අගයට compatible වෙන පරිදි මෙලෙස %d, %c,%ld,%Ld ආදි ලෙස යෙදිය යුතුය- වැඩි විස්තර ඉස්සරහට
\n - මේක දන්නවනේ මේකෙන් වෙන්නෙ නිව් ලයින් 1කට යන 1
සී වල තියෙන ඔක්කොම ඩේටා ටයිප් ටික ඔන්න තියෙනවා
char
unsigned char
short
unsigned short
short int
unsigned short int
int
unsigned int
long int
unsigned long int
long
long long
unsigned long long
float
float
double
හෙන ලෝඩ් 1ක තියෙනවා නේ
ඕගොල්ලො දැනට මතක තියාගන්න නිඛිල වලට int නුත් දශම තියෙන ඒවට double නුත් ගන්න-
මේ පෝග්රෑම් එක බැලුවම තේරෙයි මේ ටයිප් වල සයිස් ගැන
include <stdio.h>
int main(){
char ch;
unsigned char uch;
short s;
unsigned short us;
short int si;
unsigned short int isi;
int i;
unsigned int ui;
long int li;
unsigned long int uli;
long l;
long long ll;
unsigned long long ull;
float f;
float lf;
double d;
long double ld;
printf("size of char %d\n",sizeof(ch));
printf("size of unsigned char %d\n",sizeof(uch));
printf("size of short %d\n",sizeof(s));
printf("size of unsigned short %d\n",sizeof(us));
printf("size of short int %d\n",sizeof(si));
printf("size of unsigned short int %d\n",sizeof(isi));
printf("size of int %d\n",sizeof(i));
printf("size of unsigned int %d\n",sizeof(ui));
printf("size of long int %d\n",sizeof(li));
printf("size of unsigned long int %d\n",sizeof(uli));
printf("size of long %d\n",sizeof(l));
printf("size of long long %d\n",sizeof(ll));
printf("size of unsigned long long %d\n",sizeof(ull));
printf("size of float %d\n",sizeof(f));
printf("size of float %d\n",sizeof(lf));
printf("size of double %d\n",sizeof(d));
printf("size of long double %d\n",sizeof(ld));
return 0;
}
printf("%d\n",x); මෙන්න මේ වගේ ඩේටා ටයිප් වලට අනුරෑපව ප්රින්ට් කරනකොට ඔන වෙන %d වගේ ඒවා ගැන මේ පහල පෝග්රම් 1න් අදහස ගන්නකෝ////////////////////////////////
#include <stdio.h>
int main(){
char ch='A';
unsigned char uch='B';
short s=100;
unsigned short us=200;
short int si=300;
unsigned short int isi=400;
int i=500;
unsigned int ui=600;
long int li=1000;
unsigned long int uli=3000;
long l=1000;
long long ll=6000;
unsigned long long ull=50000;
float f=1.5;
double d=1.34343;
long double ld=45.54554;
printf("char : %c\n",ch);
printf("unsigned char : %c\n",uch);
printf("short : %d\n",s);
printf("unsigned short : %d\n",us);
printf("short int : %d\n",si);
printf("unsigned short int : %d\n",isi);
printf("int : %d\n",i);
printf("unsigned int : %d\n",ui);
printf("long int : %ld\n",li);
printf("unsigned long int : %ld\n",uli);
printf("long : %ld\n",l);
printf("long long : %Ld\n",ll);
printf("unsigned long long : %Lu\n",ull);
printf("float : %f\n",f);
printf("double : %f\n",d);
printf("long double : %lf\n",d);
return 0;
}
මතක තියාගන්න අපි වේරිබල් 1ට අගයක් assign කරේ නැතත් සී වලින් ඒකට මොකක්හරි කුණු අගයක් දා ගන්නවාග මේකට කියන්නේ garbage value දාගන්නවා කියල
#include<stdio.h>
int main(){
int x;
printf("%d\n",x);
return 0;
}
මේක රන් කරල බැලුවම තේරෙයි ඒක- ගනන් ගන්නෙපා සී පිස්සු ලෝකයක් කියල හිතෙයි- අවුලක් නෑ අපි ඉස්සරහට පාඩම අරන ්යංමේ ඩේටා ස්ටෝ කරනකොට යම් ඇඩ්රස් 1ක් තියාගන්නව- ඕගොල්ලන්ගෙ ගෙදරට ලියුම් එන්නෙ අන්න අ් වගේ ඒකෙන් වේරිබල් 1 නිශ්චිත ඇඩ්රස් 1ක තියාගන්නව
ඒ ඇඩ්රස් 1 ගන්නෙ වේරිබල් නමට ඉස්සරහින් & දාල_
බලන්නකෝ පහල උදා හ ර ණේ
මේ ඇඩ්රස් ප්රින්ට් කරනකොට %p ගන්නෙ හරිද
#include <stdio.h>
int main(){
int x=100;
printf("x : %d\n",x);
printf("address x : %p\n",&x);
return 0;
}
June 14, 2013
June 13, 2013
Chapter 2 ස්පෙෂල් චාර් (Special Char)
Special Char ටිකක් අදුරගමු-
ඔයාල විවිධ වචන ටයිප් කරනකොට ඒ වගේම ජේද වවන සෙට් ටයිප් කරනකොට මෙන්න මේ මම පහලින් දාන Special Char ටික හරි වැදගත් වෙනව-
\n - new line ( සී වලදි මේක නම් ගොඩක් ඕන වෙනව)
\b - backspace
\t - tab
\a - System bell
\\ - print \
\" - print "
\' - print '
මේ උදාහරණ ටික බලන්නකෝ - මේවගෙන් ඔයාට සිරාවටම මේ ස්පෙශල් චා ටික චා කරගන් නැතිව ගොඩ දා ගන්න පුලුවන්-
"\n"
#include<stdio.h>
int main(){
printf("Hello\nC !\n");
return 0;
}
/////////////////////////////////////////////////////////////
"\t"
#include<stdio.h>
int main(){
printf("Hello\tC !\n");
return 0;
}
//////////////////////////////////////////////////////////////
"\b"
#include<stdio.h>
int main(){
printf("Sinhalen\bC !\n");
return 0;
}
///////////////////////////////////////////////////////////////
"\" "
#include<stdio.h>
int main(){
printf("Sinhalen\"C !\n");
return 0;
}
///////////////////////////////////////////////////////////////////
Example
#include<stdio.h>
int main(){
printf("\"Correct\" way to learn C \nfrom Sinhalen C\t\\'C\'\n");
return 0;
}
කිව්වත් වගේ \n තමයි වැඩිපුරම ඕන වෙන්නෙ
මීළග පාඩම තවත් රසවත්--------------------------------------------
මේවයේ අවුල් තියෙන තැන් කියන්න හොදේ----------
https://www.facebook.com/groups/442878449103697/ඔබගේ සී ගැටලුවලට ක්ෂණික විසදුම් සදහා
Powered By Spectra(pvt) ltd
Established in 2012
June 10, 2013
ඔයලා හොදටම දන්න සින්හලෙන් ''සී'' ..........
සී.. වූ කලී පරිගණක භාෂාවකි.1969 සහ 1973 අවුරුදු අතර තුර සී සදා ඇත්තේ ආතර් සී. ක්ලාක් නම් නොවේ.ඒ ඩෙන්නිස් රිචී මහතා විසිනි.
Java වැනි සම්භාවනීය සුන් දර වූ භාෂාවක් තිබියදී සී වැනි කුජීත එකක් Campus එකේ Some Courses වලට ඉගෙන්වීම ගැන දැඩි ලෙස හෙලා දකින්නෙමු.සමහර විටක එය අප නොදන්නා නිසා විය හැක.ඒ උනාට හෙලා දකින්නෙමු.
Subscribe to:
Comments (Atom)


.svg.png)