>
>   Here is a simple program.
>
>   #include<stdio.h>
>
>   #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
>   int array[] = {23,34,12,17,204,99,16};
>
>   int main()
>   {
>       int d;
>
>       for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
>           printf("%d\n",array[d+1]);
>
>       return 0;
>   }
>
> This is a program to print the arrays, but is not working. I don't know why
> it is not. Please tell why this is not working.

Ofcourse, this will not work the way you intend it to!
Here, there are two subtle issues which, I think, you
either didn't notice or know.  They are:

    *   The return value of sizeof operator is size_t
        which is typedef'd in <stddef.h> as an unsigned
        integer.

    *   The second point is about C promotion rules.
        Here "d" and TOTAL_ELEMENTS are of signed and
        unsigned types, respectively.

This rule is:

    If one operand has unsigned integer type, then the operand with
    signed integer type is converted to the type of the operand with
    unsigned integer type.

Hence, in this program "d" is promoted to an unsigned type.  When
"d" is first compared with TOTAL_ELEMENTS-2, it was initialized to -1.
Since -1 is not in the range of an unsigned type, a round-about action
happens which is described by the following rule:

    If either of the operand is unsigned and the other signed, then
    the value is converted by repeatedly adding or subtracting one
    more than the maximum value that can be represented in the new
    type until the value is in the range of the new type.

In simple terms, UINT_MAX+1 is either added or subtracted from -1 till
the sum/difference is in a range representable by an unsigned int.  So
during the comparison time, the value of "d" is either (-1+UINT_MAX+1)
or (-1-(UINT_MAX+1)), which is greater than TOTAL_ELEMENTS-2.  Hence,
the loop is not entered.

>
> But below one works
>
>   #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
>   int array[] = {23,34,12,17,204,99,16};
>
>   int main()
>   {
>       int d;
>
>       for(d=-1;d <= (int) (TOTAL_ELEMENTS-2);d++)
>           printf("%d\n",array[d+1]);
>
>       return 0;
>   }

The type cast solves the problem of type mismatch.
A better solution would be like this one:

    #define TOTAL_ELEMENTS (int) (sizeof(array) / sizeof(array[0]))