08.04.2014 Views

Algorithmique et Langage - Pages de Michel Deloizy - Free

Algorithmique et Langage - Pages de Michel Deloizy - Free

Algorithmique et Langage - Pages de Michel Deloizy - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

! Initialisation <strong>de</strong> données<br />

o Exemple :<br />

void fonctionW(void)<br />

{<br />

char *t1="toto est le plus beau";<br />

→ t1 est un pointeur initialisé sur une chaîne <strong>de</strong><br />

caractères constante (à chaque appel <strong>de</strong> fonctionW)<br />

}<br />

! Initialisation <strong>de</strong> données<br />

o Exemple :<br />

void fonctionY(void)<br />

{<br />

static char *t1="toto est le plus beau";<br />

→ t1 est un pointeur initialisé au chargement du<br />

programme sur une chaîne <strong>de</strong> caractères constante<br />

chaîne)<br />

}<br />

→ t1 pourra être modifié (pour pointer sur une autre<br />

M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />

129<br />

M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />

130<br />

Fonction main<br />

! Initialisation <strong>de</strong> données<br />

o Exemple :<br />

double tab[ ]={1.0, 3.0, 5.0, 7.0};<br />

char *mots[ ]={"toto","titi","tata",0};<br />

struct {<br />

char *nom;<br />

double val;<br />

} liste[100] = {<br />

{ "pi", 3.14 },<br />

{ "x", 200.12 },<br />

};<br />

M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />

131<br />

! Démarrage du programme<br />

! Renvoie une valeur entière au système d'exploitation<br />

→ co<strong>de</strong> d'erreur<br />

! Adm<strong>et</strong> 3 paramètres :<br />

int main(int<br />

int argc, , char *argv*<br />

argv[ [ ], char *arge*<br />

arge[ [ ])<br />

! Paramètres "transmis" par le système d'exploitation<br />

! argc : nombre <strong>de</strong> paramètres sur la ligne <strong>de</strong> comman<strong>de</strong> (à l'invocation<br />

du programme)<br />

! argv : chaînes <strong>de</strong> caractères contenant les paramètres<br />

! arge : variables d'environnement<br />

M. <strong>Deloizy</strong> <strong>Langage</strong> C<br />

132<br />

33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!