#include <iostream>
using namespace std ;
main()
{  int n=10, p=20 ;
   void fct (int, int=12) ; // prototype avec une valeur par dfaut
   fct (n, p) ;             // appel "normal"
   fct (n) ;                // appel avec un seul argument
                            // fct()  serait, ici, rejet */
}
void fct (int a, int b)     // en-tte "habituelle"
{
   cout << "premier argument : " << a << "\n" ;
   cout << "second argument  : " << b << "\n" ;
}   
#include <iostream>
using namespace std ;
main()
{  int n=10, p=20 ;
   void fct (int=0, int=12) ; // prototype avec deux valeurs par dfaut
   fct (n, p) ;               // appel "normal"
   fct (n) ;                  // appel avec un seul argument
   fct () ;                   // appel sans argument
}
void fct (int a, int b)     // en-tte "habituelle"
{  cout << "premier argument : " << a << "\n" ;
   cout << "second argument  : " << b << "\n" ;
} 
#include <iostream>
using namespace std ;
struct enreg { int a ;      // type enreg defini a un niveau global
               float b ;
             } ;

main()
{ enreg x ;
  void fct (enreg y) ;
  x.a = 1 ; x.b = 12.5 ;
  cout << "avant appel fct : " << x.a << " " << x.b << "\n" ;
  fct (x) ;
  cout << "au retour dans main : " <<  x.a << " " << x.b ;
}

void fct (enreg s)
{ s.a = 0 ; s.b=1 ;
  cout << "dans fct  : " << s.a << " " << s.b << "\n" ;
}
#include <iostream>
#include <cstdarg>       // pour va_arg et va_list
using namespace std ;

void essai (int par1, char  par2, ...)
{  va_list adpar ;
   int parv ;
   cout << "premier parametre : " << par1 << "\n" ;
   cout << "second parametre  : " << par2 << "\n" ;
   va_start (adpar, par2) ;
   while ( (parv = va_arg (adpar, int) ) != -1)
       cout << "argument variable : " << parv << "\n" ;
}

main()
{  cout << "premier essai\n" ;
   essai (125, a, 15, 30, 40, -1) ;
   cout << "deuxieme essai\n" ;
   essai (6264, S, -1) ;
}
#include <iostream>
#include <cstdarg>
using namespace std ;
void essai (int nbpar, ...)
{  va_list adpar ;
   int parv, i ;
   cout << "nombre de valeurs : " << nbpar << "\n" ;
   va_start (adpar, nbpar) ;
   for (i=1 ; i<=nbpar ; i++)
     {  parv = va_arg (adpar, int) ;
        cout << "argument variable : " << parv << "\n" ;
     }
}
main()
{  cout << "premier essai\n" ;
   essai (3, 15, 30, 40) ;
   cout << "\ndeuxieme essai\n" ;
   essai (0) ;
}
#include <iostream>
using namespace std ;
main()
{  int n=10, p=20 ;
   void fct (int, int=12) ; // prototype avec une valeur par dfaut
   fct (n, p) ;             // appel "normal"
   fct (n) ;                // appel avec un seul argument
                            // fct()  serait, ici, rejet */
}
void fct (int a, int b)     // en-tte "habituelle"
{
   cout << "premier argument : " << a << "\n" ;
   cout << "second argument  : " << b << "\n" ;
}   
#include <iostream>
using namespace std ;
main()
{  int n=10, p=20 ;
   void fct (int=0, int=12) ; // prototype avec deux valeurs par dfaut
   fct (n, p) ;               // appel "normal"
   fct (n) ;                  // appel avec un seul argument
   fct () ;                   // appel sans argument
}
void fct (int a, int b)     // en-tte "habituelle"
{  cout << "premier argument : " << a << "\n" ;
   cout << "second argument  : " << b << "\n" ;
} 
#include <iostream>
using namespace std ;
struct enreg { int a ;      // type enreg defini a un niveau global
               float b ;
             } ;

main()
{ enreg x ;
  void fct (enreg y) ;
  x.a = 1 ; x.b = 12.5 ;
  cout << "avant appel fct : " << x.a << " " << x.b << "\n" ;
  fct (x) ;
  cout << "au retour dans main : " <<  x.a << " " << x.b ;
}

void fct (enreg s)
{ s.a = 0 ; s.b=1 ;
  cout << "dans fct  : " << s.a << " " << s.b << "\n" ;
}
#include <iostream>
#include <cstdarg>       // pour va_arg et va_list
using namespace std ;

void essai (int par1, char  par2, ...)
{  va_list adpar ;
   int parv ;
   cout << "premier parametre : " << par1 << "\n" ;
   cout << "second parametre  : " << par2 << "\n" ;
   va_start (adpar, par2) ;
   while ( (parv = va_arg (adpar, int) ) != -1)
       cout << "argument variable : " << parv << "\n" ;
}

main()
{  cout << "premier essai\n" ;
   essai (125, a, 15, 30, 40, -1) ;
   cout << "deuxieme essai\n" ;
   essai (6264, S, -1) ;
}
#include <iostream>
#include <cstdarg>
using namespace std ;
void essai (int nbpar, ...)
{  va_list adpar ;
   int parv, i ;
   cout << "nombre de valeurs : " << nbpar << "\n" ;
   va_start (adpar, nbpar) ;
   for (i=1 ; i<=nbpar ; i++)
     {  parv = va_arg (adpar, int) ;
        cout << "argument variable : " << parv << "\n" ;
     }
}
main()
{  cout << "premier essai\n" ;
   essai (3, 15, 30, 40) ;
   cout << "\ndeuxieme essai\n" ;
   essai (0) ;
}
#include <iostream>
using namespace std ;
main()
{  int n=10, p=20 ;
   void fct (int, int=12) ; // prototype avec une valeur par dfaut
   fct (n, p) ;  #include <iostream>
using namespace std ;


main()
{  void echange (int a, int b) ;
   int n=10, p=20 ;
   cout << "avant appel   : " << n << " " << p << "\n" ;
   echange (n, p) ;
   cout << "apres appel   : " << n << " " << p << "\n" ;
}
void echange (int a, int b)
{
   int c ;
   cout << "dbut echange : "<< a << " " <<  b << "\n"  ;
   c = a ;
   a = b ;
   b = c ;
   cout << "fin echange   : " << a << " " << b << "\n"  ;
}
#include <iostream>
using namespace std ;
int i ;
main()
{  void optimist (void) ;
   for (i=1 ; i<=5 ; i++)
       optimist() ;
}
void optimist(void)
{   cout << "il fait beau " << i << " fois\n" ;
}
#include <iostream>
using namespace std ;
           /***** le programme principal (fonction main) *****/
main()
{  float fexple (float, int, int) ; // dclaration de fonction fexple
   float x = 1.5 ;
   float y, z ;
   int n = 3, p = 5, q = 10 ;

         /* appel de fexple avec les arguments x, n et p */
   y = fexple (x, n, p) ;
   cout << "valeur de y : " << y << "\n" ;

         /* appel de fexple avec les arguments x+0.5, q et n-1 */
   z = fexple (x+0.5, q, n-1) ;
   cout << "valeur de z : " << z << "\n" ;
}

         /*************** la fonction fexple ****************/
float fexple (float x, int b, int c)
{  float val ;          // dclaration dune variable "locale"  fexple
   val = x * x + b * x + c ;
   return val ;
}
#include <iostream>
using namespace std ;
int n ;
main()
{ void fct (int r) ;
  int p ;
  for (p=1 ; p<=5 ; p++)
    { n = 2*p ;
      fct(p) ;
    }
}
void fct(int r)
{
  int q=n, s=r*n ;
  cout << r << " " << q << " " << s << "\n" ;
}
#include <cmath>         // ancien <math.h>    pour sqrt
#include <iostream>
using namespace std ;
  /* dfinition dune fonction en ligne */
inline double norme (double vec[3])
{  int i ; double s = 0 ;

   for (i=0 ; i<3 ; i++) 
     s+= vec[i] * vec[i] ;
   return sqrt(s) ;
}
        /* exemple dutilisation */
main()   
{  double v1[3], v2[3] ;
   int i ;
   for (i=0 ; i<3 ; i++)
   { v1[i] = i ; v2[i] = 2*i-1 ;
   }
   cout << "norme de v1 : " << norme(v1) << "\n" ;
   cout << "norme de v2 : " << norme(v2) << "\n" ;
}##include <iostream>
using namespace std ;
main()
{  void fct() ;
   int n ;
   for ( n=1 ; n<=5 ; n++)
      fct() ;
}
void fct()
{  static int i ;
   i++ ;
   cout << "appel numro : " << i << "\n" ;
}
#include <iostream>
using namespace std ;
void sosie (int) ;            // les prototypes
void sosie (double) ;
main()                        // le programme de test
{  int n=5 ;
   double x=2.5 ;
   sosie (n) ;
   sosie (x) ; 
}
void sosie (int a)            // la premire fonction
{  cout << "sosie numero I   a = " << a << "\n" ;
}
void sosie (double a)         // la deuxime fonction
{   cout << "sosie numero II  a = " << a << "\n" ;
}
#include <iostream>
using namespace std ;
main()
{  void echange (int &, int &) ;      
   int n=10, p=20 ;
   cout << "avant appel :   " << n << " " << p << "\n" ;
   echange (n, p) ;        // attention, ici pas de &n, &p
   cout << "apres appel :   " << n << " " << p << "\n" ;
}
void echange (int & a, int & b)
{  int c ;
   cout << "debut echange : " << a << " " << b << "\n" ;
   c = a ; a = b ; b = c ;
   cout << "fin echange   : " << a << " " << b << "\n" ;
}
