My C program consists of an array called 'test_var'. It has another integer array 'arr_int' that consists of a set of integer numbers. My code looks something like this:
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
int State(var);
int main()
{
int arr_int[3] ={1000, 1001, 1002, 1003};
int var;
int *test_var[4]={0};
State(var)
{
int i;
for(i=0; i<4; i++){
test_var[i] = arr_int[i];
i++;
}
return test_var[var];
}
printf("Enter a number between 0 and 3\n");
scanf("%d",&var);
State(var);
printf ("The array structure is %d", test_var[var]);
return 0;
}
However now when I try to print the returned value array test_var for the user input var=0 instead of the whole array(1000) I just get 0. What am I doing wrong here ? COuld somebody please tell me? Am I dereferencing the array in a wrong way?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire