Tύποι Δεδομένων

Click here to load reader

  • date post

    03-Jan-2016
  • Category

    Documents

  • view

    32
  • download

    0

Embed Size (px)

description

Tύποι Δεδομένων. signed/unsigned, long/short μετατροπη τυπων (αυτοματα και casting) char enum typedef strings struct. Βασικοί Tύποι Δεδομένων C. TυποςΜεγεθοςΠεδιο ΤιμωνΜοναδικες char,1byte ‘ a’..‘z’ ‘A’..‘Z’‘0’..‘9’ 2 8 ή 256 int,4 bytes-2 31 ..2 31 -12 32 - PowerPoint PPT Presentation

Transcript of Tύποι Δεδομένων

  • T signed/unsigned, long/short ( casting)charenumtypedefstringsstruct

  • T CT char,1byte a..z A..Z0..9 28 256int,4 bytes-231..231-1232float,4 bytes10-37..1038232double8 bytes10-307..10308264*4 bytes 232 (0..232 -1)

  • T int -215..215-12 bytesshort ( )0..216-12 bytesunsigned short-231 .. 2314 bytesint ( )0 .. 232-14 bytesunsigned-263..263-18 byteslong ( )0..264-18 bytesunsigned long\signed/unsigned: ! signed unsigned

  • T char -27..271 bytechar ( )0..28-11 byteunsigned charfloat, double 10-37 .. 10384 bytesfloat10-307 .. 103088 bytesdouble10-4931..10493216 byteslong double

  • A (round-off error) 0.1000001 0.1 round-off error / x==0.1, 0.999999866, 0.1000001 (overflow)char y = (char) 255;++y;Y (underflow)0.0 0.000000000000000000000000..001 (45 0s)

  • ;unsigned w = 0, x = 0xffffffff;--w;++x; y z:int y = 0xffffffff;unsigned z = 0xffffffff;

  • M () : char int float double int x=2;float y=3.0; y/x => 3.0/2.0

  • M () = = int x = 3.14; /* 3 */ float x = (2/3); /* 0.0 */Casting ( ) float x=(float) 2/3; /*2.0/3, 2.0/3.0, 0.66666*/ float x = (float) (2/3); /* 0 */

  • char C ASCII code, , (\n, \t...) 0 48, 1 49,.., 9 57A 65, , Z 90 a 97, , z 122

  • char int j;for(j=0;j
  • (Enumerated Types)enum boolean_e {FALSE, TRUE};

    enum boolean_e x; /* enum boolean_e*/

    if (x== FALSE){ }

  • (Enumerated Types):enum onoma {name0, name1, , name n};: 0, 1 enum enum_onoma onoma; enum boolean_e y;

  • (Enumerated Types) - O (global scope)

  • :enum onoma{name0=constant, name1,..};enum month_e{JAN=1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC};JAN 1, FEB 2 for(i=JAN;i
  • (Enumerated Types) enum ( enum #define) :enum day_e{Mon, Tue, Wed, Thu, Fri, Sat, Sun};enum weekday_e{Mon, Tue, Wed, Thu, Fri};

  • typedeftypedef unsigned int nsint;nsint x;: typedef type new_type;: new_type type.X ( )

  • typedeftypedef enum boolean_e boolean_t;boolean_t x;

    typedef unsigned int nsint;typedef nsint ID_TYPE;nsintfoo(nsint x, unsigned int y, ID_TYPE z){...}

  • stringsstring NULL \0char tname[]=yia sou; char tname[]={y, i, a, , s, o, u, \0}; yia sou 8 printf(%s,tname);scanf(%s,tname);/* \0 */string pointer: strings string pointer: char *

  • int strlen(char *p){int length;for(length=0;*p!=NULL;++p,++length);/*den metra NULL*/return length;}

    char tname[]=yia sou; char *pname = tname;char *ps = epl 131;

    printf(String %s has length %d characters\n,tname,strlen(tname));

  • int strlen(char *p){int length=0;while(*p!=NULL){++length;++p;}return length;}int strlen(char *p){int length=0;while(*p++!=NULL){++length;}return length;}

  • int strlen(char *p){char *t = p;while(*p++);return (int) (p-t)/sizeof(char);}

  • string int getline(char s[], int lim) . s . To lim. .

  • intgetline(char s[], int limit){int c, k;

    for(k=0;k

  • strings

  • /struct(ures): struct struct student_s{char name[80];intid;intetos;floatvathmos;};

  • struct: o struct student_s{char name[80];intid;floatvathmos;};struct student_s student;typedef struct student_s student_t;student_t student_table[STUDENT_NUM];

  • struct: student.id = 123456;

    if (student_table[i].vathmos >8.0)++very_good_grade;

    for(i=0;i

  • struct: structsstudent_table[i]=student_table[j]; j i, . / void display_student(student_t *s) void display_student(student_t s)

  • struct: pointers void display_student(student_t s){printf(%s %6d %5.2f,s.name, s.id, s.vathmos);} struct :->voiddisplay_student(student_t *s){printf(%s %6d %5.2f,s->name, s->id, s->vathmos);}

  • struct: for(i=0;iid != p->id){...}