0
Passing Arrays into function. How do i fix the code?
#include <stdio.h> void display(int *); void show(int *); int main() { int num[]={1,2,3,4,5}, s; for(s=0; s<5; s++){ display(&num[s]); } return 0; } void display(int *x) { show(&x); } void show(int *a) { printf("%d\n", *a); //this is not printing the value. } I've tried using **a but the compiler doesn't execute, it throws a warning of incompatible pointer type.
8 Réponses
+ 1
Write in line 3
void show(int **);
and in line 17
void show( int **a)
The problem is as I mentioned before that x holds an address and show expects an address not the address to an address which is what you wanted to do by &x
0
write show(x) instead of write(&x)
0
did it not work?
0
@AKC actually the book that I'm learning from requires me to write only the show function. It had show(&x) and then said to write a show function which prints all the values.
0
ok that's a little bit confusing for me because x should be the the address not the value.
0
I know!
0
So I tried it without the "&" Then it works... But I try to figure out what the problem is when I dont modify at this position
0
And that worked! Thank you!