I am trying to pass a pointer of an array in function. In function, i am trying to reverse the array elements.After that, pointer will return to main() function. In rev() function it prints perfectly alright but in main() it only print 1st element of array and then print some garbage value.Please solve my problem.
Code:
#include<stdio.h> #include<conio.h> int *rev(int *p); main() { int a[5],*x,i,a2[5],*t; clrscr(); x=a; //t=a2; printf("\n enter the no"); for(i=0;i<=4;i++) scanf("%d",(x+i)); t=rev(x); for(i=0;i<=4;i++,t++) printf("\n%d",*t); getch(); } int *rev(int *p) { int *r,i,a1[5],j; r=a1; p=p+4; for(i=0;i<=4;i++,r++,p--) { r=p; printf("\n%d",*r); } r=r-5; printf("\n%d",*r); return r; }
Comment