While coding in C, I came across the below situation.
int function ()
{
if (!somecondition) return false;
internalStructure *str1;
internalStructure *str2;
char *dataPointer;
float xyz;
/* do something here with the above local variables */
}
Considering the if
statement in the above code can return from the function, I can declare the variables in two places.
if
statement.if
statement. As a programmer, I would think to keep the variable declaration after if
Statement.
Does the declaration place cost something? Or is there some other reason to prefer one way over the other?