Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type...
-
Upload
isabelle-gil -
Category
Documents
-
view
105 -
download
1
Transcript of Miguel Garzon CrUise Lab - SITE. Introduction Data Types and Sizes Constants Logic Operators Type...
Miguel GarzonCrUise 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
• Char: un seul byte
• Int
• Float
• Double
• Short
• Long
• #define MAXLINE 1000
char esc = ‘\\`;int i = 0;int limit = MAXLINE +1;float aFloat = 1.0e-5;const double e = 2.7856;
• +
• -
• *
• /
• % (pas applicable pour float et double)
int aEntier = 100 % 4;
printf(“%d est un entier”, aEntier);
• Relationnels:>, <, >=, <=
• Equalité:==, !=
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}
• ++ 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;
• & : AND
• ^ : Inclusive OR
• << : Exclusive OR
• >> : left shift
• ~ : one’s complement
• Comme en java!
Else if
If-Else
Switch switch (expression)
{
case const-expr: statement
default: statements
}
• Comme en Java!do-whilewhileFor
• Goto! for ( …) {
if (disaster) goto error;
} error: printf(“bad programming!”);
• 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:
& donne l’addresse à un objet
EX. p = &c;
p pointe donc à c
* Donne accès à l’objet auquel le pointeur pointe.
int x =1;y = 2;z[10];int *ip;À vous de jouer:
ip = &x;y= *ip;
*ip =0; ip= &z[0];
swap (a,b);
void swap(int x ,int y){int temp;temp = x;x= y;
y =temp;}
gcc WriteMyString.c header.h main.c -o main