#include <stdio.h>
const int TAILLE_MAX = 10;
int iTableau[TAILLE_MAX]={3,6,0,8,97,0,5,6,0,8};

- 60,014
- 4
- 34
- 74

- 3
- 3
-
Please post all code and error messages directly in the question as text, not a picture of text and not a link to a picture of text. – dbush Nov 05 '21 at 14:25
-
#include
const int TAILLE_MAX = 10; int iTableau[TAILLE_MAX]={3,6,0,8,97,0,5,6,0,8}; int main() { int* iPointeurDeb = NULL; int* iPointeurFin = NULL; int* iCompteur = NULL; iPointeurDeb = &iTableau[0]; iPointeurFin = &iTableau[TAILLE_MAX - 1]; for(iCompteur = iPointeurDeb; iCompteur <= iPointeurFin; iCompteur++) if(*iCompteur == 0) printf("%d\n", iCompteur-iPointeurDeb); } – Lamine Nov 05 '21 at 14:32 -
Not in a comment, edit the question. And make sure it's formatted properly. – dbush Nov 05 '21 at 14:33
2 Answers
const int something = 100;
does not make the something
a constant expression. It is constant variable but not constant expression.
Static storage duration objects sizes and initializers have to be constant expressions
An integer constant expression
*
shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, and floating constants that are the immediate operands of casts. Cast operators in an integer constant expression shall only convert arithmetic types to integer types, except as part of an operand to the sizeof operator.(
*
)An integer constant expression is required in a number of contexts such as the size of a bit-field member of a structure, the value of an enumeration constant, and the size of a non-variable length array. Further constraints that apply to the integer constant expressions used in conditional-inclusion preprocessing directives are discussed in 6.10.1
In your case change it to:
#define TAILLE_MAX 10

- 60,014
- 4
- 34
- 74
const int TAILLE_MAX = 10;
is not a compile-time expression in C, so it cannot be used as a compile-time array size. Replace the expression with a macro: #define TAILLE_MAX 10
See also this StackOverflow question.

- 2,387
- 14
- 20