vendredi 5 juillet 2019

Why is the output different? (putting array in a function problem)

I want the output to be: 1 2 2 2

But why is the output: 1 2 3 4

What's wrong with this code?

#include <iostream>
using namespace std;

int arr[] = {0};

int pluss(int ar[],int a){
ar[0]++;
cout<<ar[0]<<endl;
if(a==0){
    pluss(ar,a+1);
    pluss(ar,a+1);
    pluss(ar,a+1);
    }
}

int main() {
pluss(arr,0);
return 0;
}

Aucun commentaire:

Enregistrer un commentaire