I'm pretty confused by pointers in general and I have no idea why this is happening. Normally a pointer to an array would just print out the values of an array but I have no idea why this is happening. Could someone explain why or suggest what is happening?
char *showBits(int dec, char *buf) {
    char array[33];
    buf=array;
    unsigned int mask=1u<<31;
    int count=0;
    while (mask>0) {
        if ((dec & mask) == 0) {
            array[count]='0';
        }
        else {
            array[count]='1';
        }
        count++;
        mask=mask>>1;
    }
    return buf;
    }
Expecting it to return a binary representation of dec, but printing it produces random garbage.
 
     
     
    