Top Banner
Miguel Garzon CrUise Lab - SITE
17

Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

Apr 04, 2015

Download

Documents

Isabelle Gil
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

Miguel GarzonCrUise Lab - SITE

Page 2: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• Introduction

• Data Types and Sizes

• Constants

• Logic Operators

• Type conversions

• Example

Page 3: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• hello.c#include <stdio.h>int main(void){

printf("hello, world\n");return 0;

}• Compilaton et execution:

gcc hello.c./a.out

Page 4: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• Char: un seul byte

• Int

• Float

• Double

• Short

• Long

Page 5: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• #define MAXLINE 1000

char esc = ‘\\`;int i = 0;int limit = MAXLINE +1;float aFloat = 1.0e-5;const double e = 2.7856;

Page 6: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• +

• -

• *

• /

• % (pas applicable pour float et double)

int aEntier = 100 % 4;

printf(“%d est un entier”, aEntier);

Page 7: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• Relationnels:>, <, >=, <=

• Equalité:==, !=

Page 8: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

If operand is long, convert other to long

Else if { if either is double, converts other to double}

Else if { if either is float, converts other to float}

Page 9: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• ++ et –• Comme prefix:

++counter : incrémente counter avant que sa valeur soit utilisée

• Comme suffix:counter++ : incrémente counter après que sa valeur a été utilisée

• Si n= 5 ; x = n++; x = ++n;

Page 10: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• & : AND

• ^ : Inclusive OR

• << : Exclusive OR

• >> : left shift

• ~ : one’s complement

Page 11: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• Comme en java!

Else if

If-Else

Switch switch (expression)

{

case const-expr: statement

default: statements

}

Page 12: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• Comme en Java!do-whilewhileFor

• Goto! for ( …) {

if (disaster) goto error;

} error: printf(“bad programming!”);

Page 13: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

• Pointeurs

Pointeur: groupe de cellules (2-4) qui peuvent garder une addresse

c est un char et p est un pointeur qui pointe à c

p: c:

Page 14: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

& donne l’addresse à un objet

EX. p = &c;

p pointe donc à c

* Donne accès à l’objet auquel le pointeur pointe.

Page 15: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

int x =1;y = 2;z[10];int *ip;À vous de jouer:

ip = &x;y= *ip;

*ip =0; ip= &z[0];

Page 16: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

swap (a,b);

void swap(int x ,int y){int temp;temp = x;x= y;

y =temp;}

Page 17: Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type conversions Example.

gcc WriteMyString.c header.h main.c -o main