i have written the code below which should print the value int the first array location
<CODE>
#include<stdio. h>
int arr(int *n)
{
int a[20],i;
printf("ENTER THE ELEMENTS OF ARRAY:");
for(i=0;i<*n;i+ +)
scanf("%d",&a[i]);
return a;
}
main()
{
int a[50],i,s,*val;
printf("ENTER THE SIZE OF THE ARRAY:");
scanf("%d",&s);
val=arr(&s);
fflush(stdout);
printf("THE RETURNED ARRAY IS:%d",*val);
}
</CODE>
Though there are no errors,i am getting few warnings
retarr.c: In function ‘arr’:
retarr.c:8: warning: return makes integer from pointer without a cast
retarr.c:8: warning: function returns address of local variable
retarr.c: At top level:
retarr.c:11: warning: return type defaults to ‘int’
retarr.c: In function ‘main’:
retarr.c:15: warning: assignment makes pointer from integer without a cast
retarr.c:12: warning: unused variable ‘i’
retarr.c:12: warning: unused variable ‘a’
retarr.c:18: warning: control reaches end of non-void function
how to make the program print the value present in first location of the array,which i have given as input?
please help
thanks in advance
<CODE>
#include<stdio. h>
int arr(int *n)
{
int a[20],i;
printf("ENTER THE ELEMENTS OF ARRAY:");
for(i=0;i<*n;i+ +)
scanf("%d",&a[i]);
return a;
}
main()
{
int a[50],i,s,*val;
printf("ENTER THE SIZE OF THE ARRAY:");
scanf("%d",&s);
val=arr(&s);
fflush(stdout);
printf("THE RETURNED ARRAY IS:%d",*val);
}
</CODE>
Though there are no errors,i am getting few warnings
retarr.c: In function ‘arr’:
retarr.c:8: warning: return makes integer from pointer without a cast
retarr.c:8: warning: function returns address of local variable
retarr.c: At top level:
retarr.c:11: warning: return type defaults to ‘int’
retarr.c: In function ‘main’:
retarr.c:15: warning: assignment makes pointer from integer without a cast
retarr.c:12: warning: unused variable ‘i’
retarr.c:12: warning: unused variable ‘a’
retarr.c:18: warning: control reaches end of non-void function
how to make the program print the value present in first location of the array,which i have given as input?
please help
thanks in advance
Comment