Can you define a constant using the const
keyword in C.
I am finding conflicting information.
Used the #define macro and hard code the value to test. The code will compile in those cases but is throwing an error when I use the const keyword.
int main(void){
const int TESTARRAYSIZE = 7;
float user_array[TESTARRAYSIZE] = {5.1, 7.2, 5.1, 8.45, 23.0,
67.123, 5.1};
float number_in_question = 5.1;
float frequency;
frequency = user_array[1];
printf("%.2f", frequency);
return(0);
}
compile error:
<filename>:22:3: error: variable-sized object may not be initialized
but this error largely seems to be coming because the constant isn't setting the value.