OVH Cloud OVH Cloud

passage par réference?

21 réponses
Avatar
jmarc
quand j'écris ces lignes qu'est ce qui gene le compilateur,
j'ai indiqué la ligne en erreur,
moi je trouve ca plus facile qu'avec des pointeurs!!
(ce programme calcul la suite de fibonacci jusqu'à 10)
merci

#include <iostream>
using namespace std;

void calculsuite(int *);
void inittab(int *);
void afftab(int *);

void main()

{
int * tab=new int[10];
inittab(tab); /*erreur à la compilation ne peut convertir int [10] en int
&*/
calculsuite(tab);
afftab(tab);
}

void calculsuite(int *t)
{
int a,b,sauv;
a=1;
b=2;
for (int j=1;j<10;j++)
{
cout<<a<<"\n";
t[j]=a;
sauv=b;
b=a+b;
a=sauv;
}
}


void inittab(int * t)
{
for (int j=1;j<10;j++) t[j]=0;
}

void afftab(int * t)
{
for (int j=1;j<10;j++) cout<<t[j]<<"\n";
}

1 réponse

1 2 3
Avatar
Fabien LE LEZ
On 25 Nov 2004 00:22:30 -0800, :

Tu aurais le même problème avec « new (int)[ 10 ] ».


Certes. Mais on est moins tenté de l'écrire.


--
;-)

1 2 3