Manipulation d'adresse.
-
- Exemple 1. Permutation
-
-
- #include <stdio.h>
-
-
- void permut1(int a, int b)
- {
- int c;
-
- printf("AVANT: a=%d \t b=%d \n",a,b);
- c=a;a=b;b=c;
- printf("APRES: a=%d \t b=%d \n",a,b);
- }
-
- void permut2(int *a, int *b)
- {
- int *c;
-
- printf("AVANT: a=%d \t b=%d \n",*a,*b);
- *c=*a;*a=*b;*b=*c;
- printf("APRES: a=%d \t b=%d \n",*a,*b);
- }
-
-
- main ()
- {
- int u,v;
- u=2;v=3;
- permut1(u,v);
- printf("Permut1:\t u=%d \t v=%d \n",u,v);
- /*---------------------------*/
- permut2(&u,&v);
- printf("Permut2:\t u=%d \t v=%d \n",u,v);
- }
Exemple 2. tableau et pointeur
- #include <stdio.h>
-
- void tmp( int *q, int val);
- void tmp( int *q, int val)
- {
- *q=val;
- }
-
- main()
- {
- int v[10],*q;
- tmp(v,3);
- tmp(&v[1],4);
- q=v;
- printf("\nv[%d]=%d\n",0,*q);
- q++;
- printf("\nv[%d]=%d\n",1,*q);
- }
-