Η Γλώσσα C - Μάθημα 3

Click here to load reader

  • date post

    21-Jan-2017
  • Category

    Education

  • view

    1.581
  • download

    0

Embed Size (px)

Transcript of Η Γλώσσα C - Μάθημα 3

  • H C

    3:

  • .

    1.

    2.

    1.

    1.

    2.

    3.

    2.

    3.

    1.

    2.

    3.

    4.

    4.

    1. typedef

    .

    1.

    2.

    1. #define

    2. H - const

    .

    2 , C, 3:

  • 3 , C, 3:

    .

    C :

    ,

    ,

    .

    ,

    .

    ,

    (. x), (.. x 1000),

    (. x=3)

    (. x )

    x c y

    2 6 4 1000 1004 1008

  • A. 1.

    4 , C, 3:

    . ()

    , :

    ( )

    (a-z, A-Z)

    (0-9)

    underscore ( _ )

    underscore ( ).

    - (case-sensitive). sum

    sUm Sum.

    - (

    , include ..)

  • A. 1.

    5 , C, 3:

    :

    ,

    . ..

    , sum,

    .. z.

    .

    2

    :

    N _, .. interest_rate

    2 , .. interestRate

  • A. 2.

    6 , C, 3:

    .

    .

    .

    ,

    .

    ,

    ,

    - 2

    15

    ,

    ...

  • A. 2. 1.

    7 , C, 3:

    C .

    ,

    bytes .

    :

    (char, int, long, short)

    (float, double)

  • A. 2. 1. (1. )

    8 , C, 3:

    ,

    .

    : bytes

    , :

    bytes

    char 1 -128 127

    short 2 -32768 32767

    int 4 -2147483648 2147438647

    long 4 -2147483648 2147438647

  • A. 2. 1. (2. )

    9 , C, 3:

    ,

    .

    9

    .

    bytes

    unsigned char 1 0 255

    unsigned int 2 0 65535

    unsigned int 2 0 65535

    unsigned long 4 0 4294967295

  • A. 2. 1. (3. )

    10 , C, 3:

    float double bytes

    ( ) .

    :

    float 7

    double 19 .

    bytes

    float 4 1.2x10-38 3.4x1038

    double 8 2.2x10-308 1.8x10308

    float 4 1.2x10-38 3.4x1038

    double 8 2.2x10-308 1.8x10308

  • A. 2. 1.

    11 , C, 3:

    .

    .

    :

    int:

    long:

    float:

    double:

  • A. 2. 1.

    12 , C, 3:

    bytes

    .

    sizeof bytes

    .( )

    .

    /* sizes.c: Provallei stin othoni ta megethi se bytes twn tipwn dedomenvn */

    #include

    main()

    {

    printf("\nTa bytes enos char einai: %d", sizeof(char));

    printf("\nTa bytes enos short einai: %d", sizeof(short));

    printf("\nTa bytes enos int einai: %d", sizeof(int));

    printf("\nTa bytes enos long einai: %d", sizeof(long));

    printf("\nTa bytes enos unsigned short einai: %d", sizeof(unsigned short));

    printf("\nTa bytes enos unsigned int einai: %d", sizeof(unsigned int));

    printf("\nTa bytes enos unsigned long einai: %d", sizeof(unsigned long));

    printf("\nTa bytes enos float einai: %d", sizeof(float));

    printf("\nTa bytes enos double einai: %d", sizeof(double));

    }

  • A. 2. 2.

    13 , C, 3:

    ( ),

    :

    ( ).

    .

    .

    . .

  • A. 3. 1.

    14 , C, 3:

    , .

    :

    _

    _

    ,

    :

    3

    .

    _ _;

    _ _1, _2, _3;

  • A. 3. 2.

    15 , C, 3:

    :

    3 x,y,z

    2 percent, amount

    :

    .

    int x,y,z;

    float percent, amount;

    int x;

    int y;

    int z;

    float percent, amount;

    ,

    .

    :

    int x,y,z

    :

    x z y

  • A. 3. 3.

    16 , C, 3:

    :

    .

    , , bytes

    .

    :

    ..

    5

    5.5 4.44 .

    int x=5;

    float y=5.5, z=4.44;

  • A. 3. 3.

    17 , C, 3:

    x 5.

    :

    ! = ( )

    , .

    ( )

    .

    int x=5;

    int x;

    x=5;

  • A. 3. 4.

    18 , C, 3:

    12: ,

    .

    :

    main

    .

    , main

    ,

    .

    ( main)

    ( main

    )

  • A. 3. 4.

    19 , C, 3:

    12: ,

    .

    :

    main

    .

    , main

    ,

    .

    ( main)

    ( main

    )

    #include

    int function(int x); //

    int g; /* g . main f */

    main()

    {

    int m; /* m . main */

    ...( main)...

    }

    int function(int x) // {

    int k; /* H k . f() */

    ...( function)...

    }

  • A. 4. 1. - typedef

    20 , C, 3:

    H C .

    typedef :

    __

    __

    , int akeraios,

    int

    typedef #include

    .

    typedef.

    typedef __ __;

    typedef int akeraios;

  • A. 4. 1. - typedef

    21 , C, 3:

    12: ,

    .

    :

    main

    .

    , main

    ,

    .

    ( main)

    ( main

    )

    /* typedef.c: Paradeigma xrisis tis entolis typedef */

    #include

    typedef int akeraios;

    main()

    {

    akeraios x,y,z;

    printf("Dwste enan akeraio: ");

    scanf("%d",&x);

    printf("Dwste akomi enan akeraio: ");

    scanf("%d",&y);

    z=x+y;

    printf("To athroisma toys einai: %d", z);

    }

  • A. 4. 1. - typedef

    22 , C, 3:

    m .

    .

    (

    ), typedef !

  • . 1.

    23 , C, 3:

    ,

    ( .. )

    C, ,

    , .

    3 ( )

    :

    . .. 2,

    C

    (int)

    . C 2 :

    ( . ) (.. 3.45)

    (.. 1.23e6

    1.23x106=1230000)

  • . 2.

    24 , C, 3:

    ,

    .

    (..

    ),

    .

    .

    , :

    #define

    const

    m. .

    , :

    #define

    ( )

    const

    .

  • . 2. 1. #define

    25 , C, 3:

    #define :

    :

    ! !

    #define #include.

    define PI

    .

    PI

    #define _ _

    #define PI 3.1415

  • . 2. 2. - const

    26 , C, 3:

    ,

    .

    const .

    ! !

    100 :

    !

    const

    ( main)

    const int x=100;

  • . 2. 2. - const

    27 , C, 3:

    const

    .

    ,

    !

    , ,

    .

    .

    C,

    .

  • . 4. 2. - const

    28 , C, 3:

    const

    .

    ,

    !

    , ,

    .

    .

    C,

    .

    /* statheres.c: Programma poy deixnei tin xrisi statherwn */

    #include //1.grafoume ta arxeia kefalidas

    #define N 100 //2.Grafoume odigies define statherwn

    //3. Edw mporoume na orisoume katholikes metavlites

    //4. Edw mporoume na orisoyme prwtotipa sinartisewn

    main()

    {

    //5.1 Dilwsi statherwn kai metavlitwn tis main int i,sum;

    const int number=10;

    //5.2 entoles tis main

    for (i=number; i

  • . 1

    29 , C, 3:

    C :

    1. 100 const

    2.

    3.

    4.