Created
April 12, 2012 11:19
-
-
Save PhDP/2366615 to your computer and use it in GitHub Desktop.
Expliquer le concept de scope
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
int a = 1; | |
int b = 2; | |
{ | |
int a = 3; // Ce 'a' est complètement différent du premier 'a' | |
a += 10; // Cherche un 'a' dans ce scope, il est trouve un (celui qui vaut 3). | |
int c = 5; | |
printf("%d\n", a); // Donne 13 | |
printf("%d\n", b); // Donne 2. Ici il ne trouve pas de 'b' déclarer dans ce scope mais il cherche dans le scope précédent et trove 'b'. | |
printf("%d\n", c); // Donne 5. | |
} // <--- Le deuxième 'a' et 'c' cesse d'exister ici | |
printf("%d\n", a); // Donne 1 | |
printf("%d\n", b); // Donne 2 | |
printf("%d\n", c); // Erreur: C est out of scope. | |
} // <--- Le premier 'a' et 'b' cesse d'exister ici. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment