Skip to content
Snippets Groups Projects
Commit 2fdadf45 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

ajouts etmise en page

parent e3e335ed
No related branches found
No related tags found
No related merge requests found
......@@ -46,9 +46,9 @@
```C
char *c; // déclaration pointeur de char
*c = 'a'; // assignation de 'a' dans la valeur pointée par c
*c = 'a'; // assign. 'a' à valeur pointée par c
c = 1000; // on modifie l'adresse pointée par c
char d = *c; // on essaie de lire la valeur pointée par c... argl!
char d = *c; // on lit la valeur pointée par c. UB!
```
- `NULL`{.C} (ou `0`{.C}) est la seule adresse **toujours** invalide.
......@@ -101,9 +101,11 @@
- Syntaxe:
```C
type identificateur(paramètres) { // variables optionnelles
type identificateur(paramètres) {
// variables optionnelles
instructions;
return expression; // type donne le type d'expression
// type expression == type
return expression;
}
```
......@@ -170,8 +172,8 @@
- Les arguments d'une fonction ne peuvent **jamais** être modifiés.
```C
void set_to_two(int a) { // a est une nouvelle variable
// la valeur de a une copie de celle passée en argument
void set_to_two(int a) { // a: nouvelle variable
// valeur de a est une copie de x
// lorsque la fonction est appelée, ici -1
a = 2; // la valeur de a est fixée à 2
......@@ -379,18 +381,62 @@ do {
```C
void foo(int tab[]) { // sans taille...
for (int i = 0; i < ?; ++i) { // on sait pas
for (int i = 0; i < ?; ++i) {
// on sait pas quoi mettre pour ?
printf("tab[%d] = %d\n", i, tab[i]);
}
}
// avec taille, [n] pas obligatoire
void bar(int n, int tab[n]) { // n doit venir avant tab ici
// n doit venir avant tab, [n] opionel
void bar(int n, int tab[n]) {
for (int i = 0; i < n; ++i) {
printf("tab[%d] = %d\n", i, tab[i]);
}
}
```
# Les tableaux (5/N)
## Quels sont les bugs dans ce code?
```C
#include <stdio.h>
int main(void) {
char i;
char a1[] = { 100,200,300,400,500 };
char a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
a2[10] = 42;
for (i = 0; i < 5; i++) {
printf("a1[%d] = %d\n", i, a1[i]);
}
return 0;
}
```
# Les tableaux (6/N)
## Quels sont les bugs dans ce code?
```C
#include <stdio.h>
int main(void) {
char i;
// 200, .., 500 char overflow
char a1[] = { 100,200,300,400,500 };
char a2[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
a2[10] = 42; // [10] out of bounds
for (i = 0; i < 5; i++) {
printf("a1[%d] = %d\n", i, a1[i]);
}
return 0;
}
```
<!-- TODO quiz: -->
<!-- que retourne sizeof(tab[]) -->
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment