Why does scanf require &?

It needs to change the variable. Since all arguments in C are passed by value you need to pass a pointer if you want a function to be able to change a parameter. Here’s a super-simple example showing it: void nochange(int var) { // Here, var is a copy of the original number. &var != … Read more

When can I omit curly braces in C?

The only places you can omit brackets are for the bodies of if-else, for, while, or do-while statements if the body consists of a single statement: if (cond) do_something(); for (;;) do_something(); while(condition) do_something(); do do_something(); while(condition); However, note that each of the above examples counts as single statement according to the grammar; that means … Read more

How sizeof(array) works at runtime?

sizeof is always computed at compile time in C89. Since C99 and variable length arrays, it is computed at run time when a variable length array is part of the expression in the sizeof operand. Same for the evaluation of the sizeof operand: it is not evaluated in C89 but in C99 if the operand … Read more