The auto keyword is used to declare local variables in C language. It has the following functions: declare local variables, which default to int type and are automatically initialized to 0 after declaration.
Usage of auto keyword in C language
auto keyword is used to declare local in C language A storage class specifier for a variable. Local variables are declared within a function or block and are valid only within that function or block. The auto keyword can be used to declare various data types such as integers, floating point numbers, characters, and structures.
The role of auto
The auto keyword has the following functions:
Usage of auto
The usage of auto keyword is as follows:
<code class="c">auto var_name;</code>
where var_name
is the variable name.
Comparison of auto and register keywords
auto and register are both storage class specifiers for local variables, but there are subtle differences between them:
Example
The following example shows the use of the auto keyword:
<code class="c">#include <stdio.h> int main() { auto int i; auto float f; i = 10; f = 20.5; printf("i = %d\n", i); printf("f = %f\n", f); return 0; }</code>
Output:
<code>i = 10 f = 20.500000</code>
The above is the detailed content of How to use auto in c language. For more information, please follow other related articles on the PHP Chinese website!