I new to pointers so i have a bit of a problem. i have a simple program to outprint random int values betwenn 0-100. But its only printing the first value and after that i'm getting a Segmentation fault (core dumped)
#include <stdio.h>
#include <stdlib.h>
void printArray(int **array, int size)
{
int i;
for (i=0; i<size; i++)
{
printf("index[%d] = %i \n",i,*array[i]);
}
}
int main()
{
int size = 10;
int *array = (int *) malloc (sizeof(size));
int i;
for (i=0; i<size; i++)
{
array[i] = rand() % 100 + 1;
}
printArray(&array,size);
free(array);
return 0;
}
I'm really not sure why, any help. thanks :)
malloc.int *array = (int *) malloc (sizeof(size));Right ->int *array = malloc (sizeof(*array * size));&and two*(and some confusion)