Title: ??as??p?s? t?? C (
1??as??p?s? t?? C (µ???d?? a????s??)
- ?st???a
- ??µ? ?a? St???e?a C p????aµµat??
- S??ta?? ?a? S?µas??????a
- ??a??s? s?µpe??f??a? µe Trace Table
2?st???a C
- ??apt?????e a??e? 1970
- Kernighan and Ritchie The C Programming
Language, 1978 - G?a Systems OS ?a? µeta???t?ste?
- p??? p?? e??e?a? ???s?? s?µe?a
- ???t?p? ANSI C (1988)
3?a??de??µa ?????aµµa
/ paradeigma programma / include
ltstdio.hgt void main() printf(First C
Program\n)
E?a???? ?????aµµat??
First C Program gt
4S?µas??????a (semantics)
S????a
/ paradeigma programma /
?d???e? p??? p??epe?e??ast? ??a s?µpe??????
ß?ß????????
include ltstdio.hgt
void main()
???sµ?? s??a?t?s?? main ?a?e p????aµµa e?e? main
?????e? pe??e???? (s?µa) e?t??e? t?? s??a?t?s??
main
printf(First C Program\n)
??t??? ?a?e? s??a?t?s? ß?ß???????? ??a e?a???? -
pa?aµet??? a???????a ?a?a?t????
5/ programma poy ypologizei athroisma dyo
akeraiwn arithmwn / include ltstdio.hgt void mai
n() int numbera, numberb / inputs/ int
sum printf(Enter two numbers
) scanf(dd,numbera, numberb) sum
numbera numberb printf(The sum of d and d
is d\n, numbera, numberb, sum)
6??a????
Enter two numbers
34 -12
The sum of 34 and -12 is 22
gt
foo
Enter two numbers
3 0
The sum of 3 and 0 is 3
gt
7/ programma poy ypologizei athroisma dyo
akeraiwn arithmwn /
S????a
??ß??????? ??a ?/?
include ltstdio.hgt
void main()
S??a?t?s? main
????se?? a?e?a?e? µetaß??te?
int numbera, numberb / inputs/ int sum
printf(Enter two numbers ) scanf(dd,nu
mbera, numberb)
??t??e? µe s??a?t?se?? stdio ??s?d??
ded?µe??? µetaß??te? ep??ta? ap? t?? te?est?
d?e????s??
sum numbera numberb
e?t??? te?est?? (operator) p??s?es?? d?ad????
te?est?? d?? te?esta???? (operands) te?est??
a?a?es??
printf(The sum of d and d is
d\n, numbera, numberb, sum)
??t??? µe s??a?t?s? stdio ??a???? ded?µe???
8Ge???e? ?a?at???se??
- Kata???ta )
- ?a? ta d?? e???? main
- ??e? ?? e?t??e? ?a? d???se?? te?e?????? µe
- ???s? s??a?t?se?? stdio (printf, scanf)
- printf e?t?p??e?
- \n ???e? t?? d??µea (cursor) st?? ep?µe?? ??aµµ?
- scanf d?aßa?e? ap? t?? ???st?
- pa???e? d?e????s? µetaß??t??, pa???e? t?µ?
9??µ? p????aµµat?? C
/ s????a / / ?d???e? st?? p??epe?e??ast?
/ / d???se?? sta?e???, µetaß??t??/ /
???sµ?? s??a?t?se?? / / ???sµ?? s??a?t?s??
main /
10??µ? p????aµµat?? C (s??.)
- ?? p????aµµa µp??e? ?a ap?te?e?ta? ap? e?a ?
pe??ss?te?a a??e?a - C e??a? d?ad??as?a?? ???ssa
- s??a?t?se?? (functions)
- µetaß??te? (variables)
11S????a
- S??ta?? ?e?????? µe / ?a? te?e?????? µe /
- ?aµµ?a s?µas?a a??a p??? s?µa?t??? µe??? e???
p????aµµat?? (te?µ????s?)
/ auto einai ena syntaktika ortho sxolio/
/ kai auto einai syntaktika ortho /
12S????a (s??.)
/ auto ti einai / /auto???
/ / lathos sxolio / giati
/ / einai lathos??? /
13include
- ?d???a st?? p??epe?e??ast? ??a e?s?µat?s?
ß?ß???????? - ??a ß?ß??????? (library ? header file) e??a? µ?a
s?????? ???s?µ?? s??a?t?se?? ?a? sta?e??? - S??ta?? include ltheader filegt
- p? include ltstdio.hgt
14include (s??.)
- ??s?µat?s? ep?t?epe? t?? ???s? s??a?t?se?? ?a?
sta?e??? µ?a? ß?ß???????? - p? ? ß?ß??????? stdio pe????e?, a??µesa se ???a,
t?? s??a?t?se?? printf, ??a e?t?p?s? p????f?????,
?a? scanf, ??a e?sd??? p????f????? - ???e? d?ata?e? st?? p??e?e??ast?
- define, ifdef, if, else, endif, undef
15???µata st?? C
- G?a sta?e?e?, µetaß??te?, s??a?t?se??
- ? C e??a? CASE SENSITIVE, ?efa?a?a ?a? µ???a
??aµµata e??a? d?af??et??a - foo ?a? FOO e??a? d?? d?af??et??a ???µata
- ???s?µ?p??ata? a?t?epe????µat??a ???µata
- ???µata de? p?epe? ?a ???s?µ?p????? desµe?µe?e?
?e?e??
16?e?µesµ??e? ???e??(Reserved Words)
- ?e?e?? µe e?d??? s?µµas?a ??a t?? C. ?e? p?epe?
?a ??????ta? ?a?a sa? ???µata
17S??ta?? ???µat??
p? metavliti rectangle_area _index_123
1variable super se tria meroi
L letters a-z A-Z N numbers 0-9 _ underscore
18S?µµas?a ?etaß??t??
- ?p????e?s? ?a? a?a???s? t?µ??
- ?a?e µetaß??t? e?e?
- t?p?
- ßas???? int, char, float, double
- µe?e??? 4?, 1?, 4?, 8? (?a?e ???e??da 1
Byte) - (s?µß?????) ???µa
- t? ???µa a?t?st???e? se s???e???µe?? d?e????s?
st?? µ??µ? - t?µ?
??a?tata? ap? t? ?e?t??????? s?st?µa
19S?µas?a ?etaß??t??
???µa (d?e????s?)
t?p??
t?µ?
int count
0 ... ...
count 137
98760060
count count 142
foo(count)
??e????s? t?? count
t?p?? d?e????s?? ???µa?eta? de??t?? (pointer)
p? int deikths
20S?µas?a ?etaß??t?? (s??.)
- ??epe? ?a d????eta? p??? ???s?µ?p????e?
- ?a? ß??s?eta? sta a??ste?a te?est? a?a?es?? ?
t?µ? t?? ap?te?esµat?? t?? e?f?as?? (expression)
sta de??a t?? ap????e?eta? st?? d?e????s? t??
µetaß??t??
?????? ???s?µ?p??e?ta? ? t?µ? t?? µetaß??t??
21????s? ?etaß??t?? (variable)
char letter int count, sum float area, double
volume int index cost double charge float
angle, income
22????s? Sta?e?a? (constant)
????s? sta?e?a?
???µa
define
t?µ?
define PI 3.1453 define YES 1 define
NO 1 define TRUE 1 define PISQUARE
PIPI define ERROR_SPACE_MESSAGE errorrun out
of space
23S?µas?a Sta?e?a?
- Sta?e?e? e????
- t?µ?
- ???µa ??? ?µ?? d?e????s?
- µeta???t?st?? a?t??a??sta t? ???µa µe t?? t?µ?
- ??e??????e?
- t??p?p???se??
- d?aßasµa e??? p????aµµat?? (PI ? 3.1453)
24??p?? ?ed?µ????
- ??a? t?p?? ded?µ???? e??a? ??a s????? t?µ?? ?a?
??a s????? ?e?t??????? (p???e??) p?? µp????? ?a
efa?µ?st??? se a?t?? t?? t?µ?? - ßas???? (char , int , float, double)
- s???et?? (arrays, unions, structs)
25char (?a?a?t??a?)
- ??apa??st? at?µ????? ?a?a?t??e? A-Z, a-z, 0-9,
!_at_, e?d??? s?µß??a \n, ?t? - ?e?e??? 1 byte. ??se? µ??ad??e? t?µe??
- ??????e?t???? t?µ?? es???e???ta? se ap?st??f???,
p.?. ???, ?a?, ?9?, ???, ? ?, ??, ?\n?, ?\??,
?t? - ?? ap?st??f?? de? ??e?????ta? ?ta? e?s????ta?
?a?a?t??e?
26int (a???a???)
- ??apa??st? a?e?a???? a???µ???
- ?e?e??? 4 bytes, ped?? t?µ?? -231-1.. 231-1
- ?a?ade??µata ??????e?t???? t?µ??
- -2189456 0 50 24562 3245 13576313
- ????e?? p??s?es? (), afa??es? (-),
p???ap?as?asµ?? (), d?a??es? (/), ?p????p? (),
?t?
27float (????t?? ?p?d?ast???? µ???? a???ße?a?)
- ??apa??st? t??? p?a?µat????? a???µ???
- ?e?e??? 4 bytes, 1x1037,1x10-37
- ????e?? p??s?es? (), afa??es? (-),
p???ap?as?asµ?? (), d?a??es? (/) - S?µe????af?a ??a ??????e?t???? t?µ??
- 1.258 ? 106 1258000.0 1.258e6 1.258E6
- 8.9 x 10-4 0.00089 8.9e-4 8.9e-4 .00089
28double (????t?? ?p?d?ast???? d?p??? a???ße?a?)
- ?d??? t?p?? µe float a??a µe µe?a??te?? a???ße?a
- ?e?e??? 8 bytes
29S??a?t?se?? (functions)
- ?a?e C p????aµµa ap?te?e?ta? ap? µ?a ?
pe??s?te?e? s??a?t?se?? - ?a?e p????aµµa e?e? µ?a s??a?t?s? main
- ??te?es?? ?e???a ap? t?? s??a?t?s? main
- S??a?t?se?? ?a????ta? (called) ?a? ep?st?ef???
(return) - ?ta? ?a????ta? pa?????? pa?aµet????
30S??ta??
ltt?p?? ep?st??f??gt lt???µa_S??a?t?s??gt(lt??sta
pa?aµet???gt) / a??? t?? s??a?t?s?? / /
d???se?? µetaß??t?? / / e?t??e? / return
lte?f?as?gt / te??? t?? s??a?t?s?? /
31S??a?t?se?? (s??.)
int display() printf(First C
Program\n) return(0)
S??a?t?s? de? pa???e? pa?aµet????
?p?st?efe? t?? t?µ? 0 0 e??a? int
32S??a?t?se?? (s??.)
S??a?t?s? pa???e? d?? pa?aµet????
int compute_sum(int a, int b) int sum sum
a b return sum
?p?st?efe? t?? t?µ? sum p?? e??a? int
33include ltstdio.hgt int compute_sum(int a, int
b) int sum sum a b return sum void
main() int numbera, numberb / inputs/ int
sum printf(Enter two numbers
) scanf(dd,numbera, numberb) sum
compute_sum(numbera, numberb) printf(The sum
of d and d is d\n, numbera, numberb, sum)
341? ?s??s?
- ???a?te t? p????aµµa p?? ?p??????e? eµßad?
?????????? ?a ?p??????e? ???? e??? ste?e??. - ?µe?oµ???a ?a??d?s?? 14/2