mardi 9 novembre 2021

Variable is correct, but test case does not execute

I wrote the following code:

#include <stdio.h>

int array[] = {23, 43, 12, 17, 204, 99, 16};
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))

int main()
{
        int test = -1,

        if (test <= TOTAL_ELEMENTS)
        {
                printf("Hello, got here!\n");
        }
}

When I compile this code (with gcc main.c -Wall (no warnings!)), and run it, the printf fails to execute. I mean, test = -1, and that is definitely smaller than the size of the array (7 digits). Where is the bug?

Aucun commentaire:

Enregistrer un commentaire