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
7684dc2c
Commit
7684dc2c
authored
5 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added advanced pointers
parent
3a1001bc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+4
-1
4 additions, 1 deletion
Makefile
index.md
+6
-1
6 additions, 1 deletion
index.md
pointeurs_avances.md
+79
-0
79 additions, 0 deletions
pointeurs_avances.md
with
89 additions
and
2 deletions
Makefile
+
4
−
1
View file @
7684dc2c
...
@@ -19,7 +19,7 @@ HTMLOPTIONS += -t html5
...
@@ -19,7 +19,7 @@ HTMLOPTIONS += -t html5
HTMLOPTIONS
+=
-c
css/tufte-css/tufte.css
HTMLOPTIONS
+=
-c
css/tufte-css/tufte.css
HTMLOPTIONS
+=
--self-contained
HTMLOPTIONS
+=
--self-contained
all
:
oral.pdf ligne_commande.pdf strings.pdf tests_assertions.pdf make.pdf base_3.pdf base_2.pdf base_1.pdf intro.pdf index.html
all
:
pointeurs_avances.pdf
oral.pdf ligne_commande.pdf strings.pdf tests_assertions.pdf make.pdf base_3.pdf base_2.pdf base_1.pdf intro.pdf index.html
intro.pdf
:
intro.md metadata.yaml
intro.pdf
:
intro.md metadata.yaml
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
...
@@ -48,6 +48,9 @@ ligne_commande.pdf: ligne_commande.md metadata.yaml
...
@@ -48,6 +48,9 @@ ligne_commande.pdf: ligne_commande.md metadata.yaml
oral.pdf
:
oral.md metadata.yaml
oral.pdf
:
oral.md metadata.yaml
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
pointeurs_avances.pdf
:
pointeurs_avances.md metadata.yaml
pandoc
$(
PDFOPTIONS
)
-o
$@
$^
index.html
:
index.md
index.html
:
index.md
pandoc
-s
$(
OPTIONS
)
$(
HTMLOPTIONS
)
-o
$@
$<
pandoc
-s
$(
OPTIONS
)
$(
HTMLOPTIONS
)
-o
$@
$<
...
...
This diff is collapsed.
Click to expand it.
index.md
+
6
−
1
View file @
7684dc2c
...
@@ -70,4 +70,9 @@ corrige: false
...
@@ -70,4 +70,9 @@ corrige: false
## Ligne de commande [PDF](ligne_commande.pdf)
## Ligne de commande [PDF](ligne_commande.pdf)
-
Point d’entrée d’un programme.
-
Point d’entrée d’un programme.
-
Conversion des arguments.
-
Conversion des arguments.
\ No newline at end of file
## Pointeurs avancés [PDF](pointeurs_fonctions.pdf)
-
Pointeurs de fonctions.
-
Pointeurs et
`const`
.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pointeurs_avances.md
0 → 100644
+
79
−
0
View file @
7684dc2c
% Pointeurs avancés
% Inspirés des slides de F. Glück
% 19 février 2020
# Pointeurs avancés
## Pointeurs de fonctions (1/2)
-
COnsidérons la fonction
`max`
retournant la valeur maximale d'un tableau
```C
int max(int *t, int size) {
int val_max = t[0];
for (int i = 1; i < n; ++i) {
if (t[i] > val_max) {
val_max = t[i];
}
}
return max_val;
}
```
-
L'appel à
`max`
, retourne l'adresse de la fonction en mémoire.
-
On peut affecter cette valeur à un pointeur.
## Pointeurs de fonctions (2/2)
-
Le type de la fonction
`max`
est
```C
int (*pmax)(int *, int);
```
-
Le type doit être déclaré avec la signature de la fonction.
-
On peut alors utiliser l'un ou l'autre indiféremment
```C
int (*pmax)(int *, int);
pmax = max;
int tab[] = {1, 4, -2, 12};
printf("%d", max(tab, 4)); // retourne 12
printf("%d", pmax(tab, 4)); // retourne 12 aussi
```
# Pointeurs et `const`
## Deux niveaux de constance
-
Le mot clé
`const`
permet de déclarer des valeurs "constantes" qui ne changeront plus en cours d'exécution du programme.
-
Mais qu'est-ce que cela veut dire pour les pointeurs?
```C
int n = 12;
const int *p = &n; // la valeur *p est const, p non
int const *p = &n; // la valeur *p est const, p non
int *const p = &n; // la valeur p est const, *p non
const int *const p = &n; // la valeur p et *p sont const
```
## Exemples
```
C
int n = 12; int m = 13;
const int *p = &n; // la valeur *p est const, p non
*p = m; // erreur de compilation.
p = &m; // OK
int const *p = &n; // la valeur *p est const, p non
*p = m; // erreur de compilation.
p = &m; // OK
int *const p = &n; // la valeur p est const, *p non
*p = m; // OK
p = &m; // erreur de compilation.
const int *const p = &n; // la valeur p et *p sont const
*p = m; // erreur de compilation.
p = &m; // erreur de compilation.
```
\ No newline at end of file
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