#include <stdio.h>
#define N 3
int main() {
int array[N] = {1,2,3};
int i,j;
for ( i=1; i<(1<<N); i++) {
for( j=0; j<N; j++) {
if((1<<j)&i) {
printf("%d", array[j]);
}
}
printf("\n");
}
return 0;
}
1
2
12
3
13
23
123
Now,
() has left to right associative and has greater precedence than any other operator.Precedence_Table.htm
<< left to right precedence, & has right to left precedence
For i=1
and for j=0
if((1<<j)&i)//1 will left shift 0 bit ,i.e.001+001=001
So, if becomes true for j=0, in 1st iteration
Prints 1
for j=1
if((1<<j)&i)//1 will left shift 1 bit ,i.e.010+001=000
So, not executed
for j=2
if((1<<j)&i)//1 will left shift 2 bit ,i.e.100+001=000
So, Not executed
for i=2
only
for j=1
if((1<<j)&i)//1 will left shift 1 bit ,i.e.010+010=010
So, executed a[j]=a[1]=2 Prints 2
for i=3
and for j=0
if((1<<j)&i)//1 will left shift 0 bit ,i.e.001+001=001
So, if becomes true for j=0, in 1st iteration
Prints 1
for j=1
if((1<<j)&i)//1 will left shift 1 bit ,i.e.010+010=010
So, executed a[j]=a[1]=2
Prints 2
So, print 1 2
Likewise it will print.
Complexity will be $O(N(2^N-1))$=$O(N2^N)$