Your question is C Pointer Code Tracing. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
Lutron's lighting control firmware keeps dimmer levels for a room as a small array of integers, and this helper is supposed to double every level (for a "boost" scene) before the values are pushed to the wall dimmers. On the actual hardware target — a typical 64-bit platform, 8-byte pointers and 4-byte int — it doesn't boost all of them.
#include <stdio.h>
void doubleLevels(int *levels) {
int count = sizeof(levels) / sizeof(levels[0]);
for (int i = 0; i < count; i++) {
levels[i] = levels[i] * 2;
}
}
int main(void) {
int levels[6] = {10, 20, 30, 40, 50, 60};
doubleLevels(levels);
for (int i = 0; i < 6; i++) {
printf("%d ", levels[i]);
}
printf("
");
return 0;
}
Assuming the stated 64-bit platform, tell me exactly what gets printed, then explain how you would modify doubleLevels so it correctly doubles every level in the array.