指针的动态分配怎么运行后老出现这个问题

代码:

#include
#include
#include




void main()
{
int a[50]={0};
int j=0,i=0,n=0,m=0;


printf("please input the mark(student number between 0-50)and                                    end with a number litter than 0: \n");

for(j=0;j<50;j++)
{

scanf("%d",&a[j]);
if(a[j]<0)
{
break;
}

}


int *q = (int *)malloc(j-2);


q=&a[0];

while(m==0)
{

printf("please input the student you want to search\n");


scanf("%d",&i);
printf("%d\n",*(q+i-1));

printf("if you want to continue plesae input 0,enter any to esc:\n");
scanf("%d",&m);

}

if(q!=NULL)
{
free(q);
q=NULL;
}




}

你可能感兴趣的:(input,null,search)