Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are parameters considered automatic variables?

An automatic variable is a local variable which is allocated and deallocated automatically when program flow enters and leaves the variable's scope.

So if I have a function with a parameter, does that mean the parameter's scope is the entire function, and therefore it fits the above definition? Or does it not quite fit this?

(I am unsure what category to put this question in, sorry)


1 Answers

Yes, parameters are objects with automatic storage duration.

N1570 6.9.1p9:

Each parameter has automatic storage duration; its identifier is an lvalue.

You asked about scope, which isn't directly relevant. Scope and lifetime are two different things. An identifier has a scope, the region of program text in which that identifier is visible. An object has storage duration (lifetime), which is the period during program execution in which the object logically exists. An object with automatic storage duration exists during the execution of the enclosing block; for a function parameter, it ceases to exist when the function returns. Its name is visible only within the body of the function, but the object itself can be accessed from outside its scope (for example if its address is passed to another function).

like image 189
Keith Thompson Avatar answered Dec 17 '25 22:12

Keith Thompson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!