c - Dynamically allocating an int array -


int funkcija(int broj)  {      int *niz;     int i;      *niz = (int*)malloc(broj*sizeof(int));      srand(time(null));      (i = 0; < broj; i++)     {         niz[i] = rand() % 50;         printf("%d\n", niz[i]);     }      return *niz;  } 

i need make function takes number, dynamically allocates string/sequence of numbers, initializes random numbers , returns it. assistance?

there few problems code, example, malloc() returns pointer, want assign pointer variable is pointer. in other words, should assign return value of malloc() niz , not *niz.

next, funkcija() should return pointer array of ints random values reside. return type should int *.

in continuation above logic, function should return pointer niz. if dereference niz (with *niz), returning first element of array (which not need).


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -