1. When submitting a function, can global variables be declared outside the function?
For example, if I have the C code
f(n){int a,b,c=4;dosomething;}
am I allowed to save 4 bytes as follows?
a,b,c=4;f(n){dosomething;}
I had always assumed not, but answers on Print an ascii spiral in O(log n) memory have led me to wonder.
2. EDIT: as an aside, what about this? I'm pretty sure this one is totally unacceptable, but if you think it is acceptable, please write a corresponding answer.
f(n,a,b,c){dosomething;}
Where only parameter n
is actually useful for passing information to the function and the parameters passed to a,b,c
can either take arbitrary values or the answerer specifies "the function must be called with c=4
."
Reversal of edit: As pointed out by Doorknob there are examples of this being considered accepable if the function has additional arguments but may be called with only the arguments specified in the question.
Relevant:
undefined
(ex.function f(n,a,b,c){...}; f(100)
instead offunction f(n){var a,b,c;...}; f(100)
) and default arguments (ex.def f(n,a=1,b=2,c=3):...; f(100)
instead ofdef f(n):a=1;b=2;c=3;...; f(100)
) being widely accepted as okay. You might want to clarify point 2: does this only apply to when the function actually has to be called with more arguments than specified? \$\endgroup\$f(n)
I guess it's OK, but it makes this meta post somewhat irrelevant for C as the length then becomes identical. \$\endgroup\$c
ever deviates from 4,f
becomes non-reusable. \$\endgroup\$