What is wrong with my code, everything looks fine but prints garbage. I just want to print array of elements entered by user.
Question is print 10 elements of an array entered by user. I know there are easier version of solving this problem, but I want to learn function return array technique. So, please don't suggest alternative solution, just try to fix this code. I don't see anything wrong because the address of a is passed onto m, and dereference m, to print array.
Question is print 10 elements of an array entered by user. I tried looking up videos on youtube searching function return array. I feel like scanf has something to do with it. I tried returning a but it will say function returns address of local variable... why? so I commented it. but why? it should return base address of an array right?
error:
none
enter 10 elements: 1 2 3 4 5 6 7 8 9 1
132731416707184220180041670672022018-4101503843276412416707184220180041670672022018-41015038432764123220180041670672022018-4101503843276412340041670672022018-4101503843276412345041670672022018-4101503843276412345641670672022018-41015038432764123456722018-4101503843276412345678-41015038432764123456789327641234567891
...Program finished with exit code 0
Press ENTER to exit console.
#include <stdio.h>
int main() {
int a[10], i;
printf("enter 10 elements: ");
for (i = 0; i < 11; i++) {
scanf("%d", &a[i]);
}
display(a, 10);
}
void display(int m[10], int n) {
int i;
for (i = 0; i < n + 1; i++) {
printf("%d", *(m + 1));
}
}