I am programing in C and tried to create a dynamic array using malloc
.
This is the relevant code :
int K_value(int N,int M,int K)
{
int Input,Temp_Result = 0,Result = 0;
int i,j,r = 0;
int* Main_Array = (int*) malloc(N * sizeof(int));
int* Sub_Array = (int*) malloc(M * sizeof(int));
for (i=0; i<N ;i++) // Enter Values Into the Main array
{
scanf("%d",&Input);
Main_Array[i] = Input;
} //End of For loop
When I run in debug mode I see that Main_Array
has only 1 slot
and that N = 5
. I was expecting Main_Array
to have 5 slots.
What am I doing wrong?