recategorized by
477 views
2 votes
2 votes

Consider the following C program.

#include <stdio.h>
main() {
    int arr[] = {1, 1, 2, 4, 8, 16, 32, 64};
    int i, j, val, t = 16;
    unsigned char c;
    for (i = 0; i < 256; i++) {
        c = i;
        val = 0;
        for (j = 0; j < 8; j++)
            val = val + ((c >> j) & 0x1)*arr[j];
            if (val == t)
                printf("%d\n", i);
    }
}


Trace the execution of the code inside the for loop indexed by i when i = 35.

recategorized by

1 Answer

0 votes
0 votes
the program actually gets the decimal value of c after 1 right shift.so when c=35,the binary after 1 right shift will be 10001 and its deccimal is 17.

Related questions