can someone please tell me the difference between the type of memory i am using here in the two given methods because in the first on i am getting out put as this:
5-->1893664096-->32766-->-1358605976-->2-->1893664096
and in second method i am getting this:-
5-->0-->0-->0-->2-->0
below are the codes for this:-
Method 1:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d",&n);
int arr[n];
arr[3]=2;
for(int i=0;i<n;i++)
printf("-->%d",arr[i]);
return 0;
}
Method 2:
int main()
{
int *a;
int n;
scanf("%d",&n);
a=(int*) malloc(sizeof(int)*n);
a[3]=2;
for(int i=0;i<n;i++)
printf("-->%d",a[i]);
return 0;
}