Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours_prog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
yassin.elhakoun
cours_prog
Commits
2fdadf45
Commit
2fdadf45
authored
5 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
ajouts etmise en page
parent
e3e335ed
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
base_2.md
+55
-9
55 additions, 9 deletions
base_2.md
with
55 additions
and
9 deletions
base_2.md
+
55
−
9
View file @
2fdadf45
...
...
@@ -46,9 +46,9 @@
```C
char *c; // déclaration pointeur de char
*c = 'a'; // assign
ation 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[]) -->
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment