T?p?? ?ed? - PowerPoint PPT Presentation

About This Presentation
Title:

T?p?? ?ed?

Description:

Tp ed – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 31
Provided by: yiannakis
Category:
Tags: matra

less

Transcript and Presenter's Notes

Title: T?p?? ?ed?


1
T?p?? ?ed?µ????
  • signed/unsigned, long/short
  • µetat??p? t?p?? (a?t?µata ?a? casting)
  • char
  • enum
  • typedef
  • strings
  • struct

2
?as???? T?p?? ?ed?µ???? C
  • T?p?? ?e?e??? ?ed?? ??µ?? ???ad??e?
  • char, 1byte a..z A..Z0..9 28 ? 256
  • int, 4 bytes -231..231-1 232
  • float, 4 bytes 10-37..1038 232
  • double 8 bytes 10-307..10308 264
  • de??t?? 4 bytes d?e????se?? 232
  • (0..232 -1)

3
????? ?as???? T?p?? ?ed?µ????
  • int
  • ?ed?? ?e?e??? ??p??
  • -215..215-1 2 bytes short (µe p??s?µ?)
  • 0..216-1 2 bytes unsigned short
  • -231 .. 231 4 bytes int (µe p??s?µ?)
  • 0 .. 232-1 4 bytes unsigned
  • -263..263-1 8 bytes long (µe p??s?µ?)
  • 0..264-1 8 bytes unsigned long\
  • signed/unsigned ?d?? µe?e??? d?af??et???
    s?µas?a! s?es? signed µe unsigned

4
????? ?as???? T?p?? ?ed?µ????
  • char
  • ?ed?? ?e?e??? ??p??
  • -27..27 1 byte char (µe p??s?µ?)
  • 0..28-1 1 byte unsigned char
  • float, double
  • ?ed?? ?e?e??? ??p??
  • 10-37 .. 1038 4 bytes float
  • 10-307 .. 10308 8 bytes double
  • 10-4931..104932 16 bytes long double

5
?e?????sµe?? ?ed?? ??µ??
  • ?a???
  • A?apa?astas? (round-off error)
  • p? 0.1000001 a?t? 0.1 ?
  • epa?a?aµßa??µe?? round-off error µe?e????e? ?a???
  • ?s?t?ta/a??s?t?ta x0.1, 0.999999866, 0.1000001
  • ?pe??e???s? (overflow)
  • char y (char) 255
  • y
  • Yp????? (underflow)
  • 0.0 a?t? 0.000000000000000000000000..001 (45 0s)

6
?e?????sµe?? ?ed?? ??µ??
  • ?? ?a s?µße?
  • unsigned w 0, x 0xffffffff
  • --w
  • x
  • ?? e??a? ? de?ad??? t?µ? t?? y ?a? z
  • int y 0xffffffff
  • unsigned z 0xffffffff
  • ???s??? µe s?es?a???? te?este?

7
Metat??p? ??p??
  • Se a???µ?t??e? e?f?ase?? (a?t?µata) e?a
    te?esta??? µetat?epete se a??? t?p? ea? ?pa??e?
    a???? te?esta??? p?? e??a? p?? de??a st??
    a??????? d?ata?? char int float double
    int x2float y3.0 y/x
    gt 3.0/2.0

8
Metat??p? ??p??
  • Se a?a?es? (a?t?µata) ? t?µ? sta de??a t??
    µetat?epete st?? t?p? t?? µetaß??t?? sta a??ste?a
    t?? int x 3.14 / 3 / float
    x (2/3) / 0.0 /
  • Casting (??t? µetat??p?) float x(float) 2/3
    /2.0/3, 2.0/3.0, 0.66666/ float x (float)
    (2/3) / 0 /

9
char
  • ?a?e ?a?a?t??a? a?t?st???e? se e?a µ??ad???
    ??d???
  • C ßas??eta? st? ASCII code
  • a?faß?t????, ??f?a???, e?d???? (\n, \t...)
  • 0 48, 1 49,.., 9 57
  • A 65, , Z 90
  • a 97, , z 122

10
char
  • tµ?µa p????aµµat?? p?? t?p??e? t??? ??f?a????
    ?a?a?t??e? ?a? t?? a?t?st???e? a?e?a?e? t?µe?
    t???
  • int j
  • for(j0jlt9j)
  • printf(c d\n, (char) j, j)

11
?pa???µ?t?? ??p??(Enumerated Types)
  • enum boolean_e FALSE, TRUE
  • enum boolean_e x / t?p?? enum boolean_e/
  • if (x FALSE)

12
?pa???µ?t?? ??p??(Enumerated Types)
  • S??ta??enum onoma name0, name1, , name n
  • S?µas?a
  • e?a s????? a?e?a??? sta?e???
  • p??t? sta?e?? apa???µ?s?? a?apa??st?ta? ?? 0, ?
    de?te?? ?? 1 ?t?
  • ???sµ?? apa???µ?t?? µetaß??t??
  • enum enum_onoma onoma
  • p? enum boolean_e y

13
?pa???µ?t?? ??p??(Enumerated Types)
  • Sta?e?e? apa???µ?s?? µp????? ?a ???s?µ?p???????
    µe a????? t?p??? - µeta?e??????ta? sa? a?e?a?e?
    sta?e?e?
  • ?etaß??te? t?p?? apa???µ?s?? µeta?e??????te sa?
    a?e?a?e? µetaß??te?
  • ?e? ???eta? e?e???? ??a t?? t?µe? a?a?es??
  • O?s?ast??a e??a? sta?e?e?
  • ??????ta? s?????? µeta t?? sta?e?e? (global scope)

14
?pa???µ?t?? ??p??
  • S??ta??
  • enum onomaname0constant, name1,..
  • enum month_eJAN1, FEB, MAR, APR, MAY, JUN, JUL,
    AUG, SEP, OCT, NOV, DEC
  • JAN 1, FEB 2 ?t?
  • for(iJANiltDECi)printf(d\n,i
  • p? enum incase_e NONE0, IN11, IN22, IN123,
    OUT4, EMPTY0

15
?pa???µ?t?? ??p??(Enumerated Types)
  • ?p?t?epete ???s? e??? ???µat?? µ??? se e?a enum
    (??? se a??? enum ??te ?a? define)
  • ?e? ep?t?epeta?
  • enum day_eMon, Tue, Wed, Thu, Fri, Sat, Sun
  • enum weekday_eMon, Tue, Wed, Thu, Fri

16
typedef
  • typedef unsigned int nsint
  • nsint x
  • S??ta?? typedef type new_type
  • S?µas?a new_type e??a? ?e? ???µa ??a t?? t?p? µe
    ???µa type.
  • X??s?µ? ??a ap?f??? µe?a??? ???µat?? t?p?? (p??
    a???ß? pe????af?)
  • ??a? t?p?? µp??e? ?a e?e? p???a ???µata

17
typedef
  • typedef enum boolean_e boolean_t
  • boolean_t x
  • typedef unsigned int nsint
  • typedef nsint ID_TYPE
  • nsint
  • foo(nsint x, unsigned int y, ID_TYPE z)...

18
strings
  • string e??a? e?a? p??a?a? µe ?a?a?t??e? p??
    te?e???e? µe t?? ?a?a?t??a NULL \0
  • char tnameyia sou
  • char tnamey, i, a, , s, o, u,
    \0
  • yia sou ap?te?e?ta? ap? 8 ?a?a?t??e?
  • printf(s,tname)
  • scanf(s,tname)/p??s??? \0 p??ste?e? st?
    te???/
  • string pointer s?ed?? pa?ta epe?e??as?a strings
    ???eta? µe string pointer char

19
  • int
  • strlen(char p)
  • int length
  • for(length0p!NULLp,length)/den metra
    NULL/
  • return length
  • char tnameyia sou
  • char pname tname
  • char ps epl 131
  • printf(String s has length d characters\n,
  • tname,strlen(tname))

20
  • int
  • strlen(char p)
  • int length0
  • while(p!NULL)
  • length
  • p
  • return length
  • int
  • strlen(char p)
  • int length0
  • while(p!NULL)
  • length
  • return length

21
  • int
  • strlen(char p)
  • char t p
  • while(p)
  • return (int) (p-t)/sizeof(char)

22
p?? d?aßa???µe µ?a ??aµµ? se string
  • G?a?ete t?? s??a?t?s? int getline(char s,
    int lim) p?? d?aßa?e? µ?a ??aµµ? ap? t??
    e?s?d?. ? ??aµµ? ap????e?eta? st?? p??a?a
    ?a?a?t???? s p?? e??a? pa?aµet??? t?? s??a?t?s??.
    To µe??st? µe?e??? ??aµµ?? ????eta? µe t? lim. ?
    s??a?t?s? ep?st?efe? t? µ???? t?? ??aµµ??.

23
  • int
  • getline(char s, int limit)
  • int c, k
  • for(k0kltlimit-1 (cgetchar())!\n
    c!EOF)
  • skc
  • if (c\n)
  • skc
  • k
  • sk\0
  • return k

24
strings
  • ???? ???s?µ? ß?ß??????? ltstring.hgt

25
??µe?/struct(ures)???sµ?? t?p??
  • struct ep?t?epe? t?? ???sµ? s???et?? t?p??
    ded?µe???
  • struct student_s
  • char name80
  • int id
  • int etos
  • float vathmos

26
struct o??sµ?? µetaß??t??
  • struct student_s
  • char name80
  • int id
  • float vathmos
  • struct student_s student
  • typedef struct student_s student_t
  • student_t student_tableSTUDENT_NUM

27
struct a?af??a se µe??
  • student.id 123456
  • if (student_tablei.vathmos gt8.0)
  • very_good_grade
  • for(i0iltSTUDENT_NUMi)
  • printf(s 6d 5.2f,student_tablei.name,
    student_tablei.id, student_tablei.vathmos)

28
struct a?a?es?
  • ?p?t?epeta? a?a?es? µeta?? µetaß??t?? t?p??
    structs
  • student_tableistudent_tablej
  • a?t???afe? ?a?e t?µ? t?? j st? i
  • a???, ?d?a?te?a ??a pa?aµet????. p??t?µ?te??
    pa???ate/ep?st?efeta? de??t?
  • void display_student(student_t s) a?t?
    void display_student(student_t s)

29
struct pointers
  • void
  • display_student(student_t s)
  • printf(s 6d 5.2f,s.name, s.id, s.vathmos)
  • a?af??a se µe?? struct µe de??t?
  • de??t??-gtµe???
  • void
  • display_student(student_t s)
  • printf(s 6d 5.2f,s-gtname, s-gtid,
    s-gtvathmos)

30
structa?af??a se µe?? µe de??t?
  • for(i0iltSTUDENT_NUMi)
  • display_student(student_tablei)
  • student_t s,p
  • ...
  • if (s-gtid ! p-gtid)...
Write a Comment
User Comments (0)
About PowerShow.com