mardi 25 mars 2014

working without allocating memory for array


Vote count:

0




My friend did this code. It works fine. aim was to separate every digit of number in to each element of array. But memory for a is not allocated anywhere. Any idea how this one is working?



#include<iostream>
#include<math.h>
using namespace std;

int* arrray(int num, int *x){
int len=0;
while(num!=0){
x[len]=num%10;
num/=10;
len++;
}
return x;
}
int main(){
int num1=123;
int l=0,k=0;
int *a=arrray(num1,a);
int n1[3];
for(int i=2;i>=0;i--){
n1[l]=a[i]; l++;
}

}


asked 2 mins ago






Aucun commentaire:

Enregistrer un commentaire