S
Star
I was surprised this code worked on Sun Solaris and AIX.
#include <stdio.h>
int MAX_SIZE = 10;
static void set_max()
{
printf("Before setting max MAX_SIZE is %d\n",MAX_SIZE);
MAX_SIZE = 20;
printf("After setting max MAX_SIZE is %d\n",MAX_SIZE);
}
static void print_array_size()
{
int arr[MAX_SIZE];
printf("MAX_SIZE is %d sizeof(int arr[MAX_SIZE]) is %d
\n",MAX_SIZE,sizeof(arr));
}
int main()
{
set_max();
print_array_size();
return 0;
}
This printed:
Before setting max MAX_SIZE is 10
After setting max MAX_SIZE is 20
MAX_SIZE is 20 sizeof(int arr[MAX_SIZE]) is 8
I thought it would give a compile error since MAX_SIZE is not a const
int type. So it fine not to use const for array lengths ? Appreciate
your feedback ?
#include <stdio.h>
int MAX_SIZE = 10;
static void set_max()
{
printf("Before setting max MAX_SIZE is %d\n",MAX_SIZE);
MAX_SIZE = 20;
printf("After setting max MAX_SIZE is %d\n",MAX_SIZE);
}
static void print_array_size()
{
int arr[MAX_SIZE];
printf("MAX_SIZE is %d sizeof(int arr[MAX_SIZE]) is %d
\n",MAX_SIZE,sizeof(arr));
}
int main()
{
set_max();
print_array_size();
return 0;
}
This printed:
Before setting max MAX_SIZE is 10
After setting max MAX_SIZE is 20
MAX_SIZE is 20 sizeof(int arr[MAX_SIZE]) is 8
I thought it would give a compile error since MAX_SIZE is not a const
int type. So it fine not to use const for array lengths ? Appreciate
your feedback ?