Reputation: 99
#include <stdio.h>
#include <conio.h>
const int MAX = 3;
int main() {
int var[] = { 10, 100, 200 };
int i, *ptr[MAX];
for (i = 0; i < MAX; i++) {
ptr[i] = &var[i]; /* assign the address of integer. */
_getch();
}
for (i = 0; i < MAX; i++) {
printf("Value of var[%d] = %d\n", i, *ptr[i]);
_getch();
}
return 0;
}
Upvotes: 1
Views: 41
Reputation: 144740
The definition int *ptr[MAX];
where MAX
is not a compile time constant expression is supported since C99 for automatic variables. Even defined as a const int MAX = 3
, MAX
is not considered a compile time constant in C. Your version of Visual Studio does not seem to support this syntax, but the online compiler at tutorialspoint does.
Upvotes: 1