pointers
So I have this code here, where I create an array, my question is why don't I get 0 as the output, but run time error instead?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include<stdio.h>
#include <stdlib.h>
void foo(int* ptr) {
for (int i = 0; i < 10; i++)
*(ptr + i) = i;
}
int main() {
int x = 5;
int* ptr = (int*)malloc(10 * sizeof(int));
foo(&ptr);
printf("%d\n", *ptr);
return 0;
}
|
Last edited on
Found it, I did foo(&ptr);
instead of foo(ptr);
Topic archived. No new replies allowed.