C90 (gcc), 46 bytes
r;main(c,v)int**v;{while(0<--c&*v[c])r++;c=r;}
Input is via command-line arguments (one integer per argument), output via exit code.
Try it online!
How it works
r is a global variable. Its type defaults to int and, being global, it value defaults to 0.
The function argument c defaults to int as well. It will hold the integer n + 1 for arrays of n Booleans; the first argument of main is always the path of the executable.
The function argument v is declared as int**
. The actual type of v will be char**
, but since we'll only examine the least significant bit of each argument to tell the characters 0 (code point 48) and 1 (code point 49) apart, this won't matter on little-endian machines.
The while loop decrements c and compares it to 0. Once c reaches 0, we'll break out of the loop. This is needed only if the array contains no 0's.
As long as 0<--c
returns 1, we takes the cth command-line argument (v[c]
) and extract its first character with by dereferencing the pointer (*
). We take the bitwise AND of the Boolean 0<--c
and the code point of the character (and three garbage bytes that follow it), so the condition will return 0 once a 0 is encountered, breaking out of the loop.
In the remaining case, while the command-line arguments are 1, r++
increments r by 1, thus counting the number of trailing 1's.
Finally, c=r
stores the computed value of r in c. With default settings, the compiler optimize and remove the assignment; it actually generates the movl %eax, -4(%rbp)
instruction. Since ret
returns the value of the EAX register, this generates the desired output.
Note that this code does not work with C99, which returns 0 from main if the end of main is reached.
01100
? \$\endgroup\$