I run the following code in c. Why do the two main bodies lead to different outputs
#include <stdio.h>
#include <stdlib.h>
int enqueue(int* ptr,int h,int t,int n, int v)
{
ptr[h]=v;
return 0;
}
int main()
{
int* Q=(int*)malloc(n*sizeof(int));
int h=0, t=0;
int a= enqueue(Q,h,t,n,5);
printf("%d %d ",a,Q[h]);
return 0;
}
OUTPUT: 0 5
Now if I change main function to this:
int main()
{
int* Q=(int*)malloc(n*sizeof(int));
int h=0, t=0;
printf("%d %d ",enqueue(Q,h,t,n,5),Q[h]);
return 0;
}
OUTPUT: 0 0