Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Exercise 42

C Exercise 42

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Learn how to use auto to define variables.

**Analysis:** None.

Program source code:

Example

//  Created by www.runoob.com on 15/11/9.

// Copyright (c) 2015 Runoob Tutorial. All rights reserved.

//

#include

int

main

(

)

{

   

int

i,num

;

    num

=

2

;

   

for

(

i

=

0

;

i

<

3

;

i

++

)

   

{

       

printf

(

"num variable is %d \n"

,num

)

;

        num

++

;

       

{

           

auto

int

num

=

1

;

           

printf

(

"Built-in module num variable is %d \n"

,num

)

;

            num

++

;

       

}

   

}

   

return

0

;

}

The output of the above example is:



num 变量为 2 

内置模块 num 变量为 1 

num 变量为 3 

内置模块 num 变量为 1 

num 变量为 4 

内置模块 num 变量为 1 

100 Classic C Language Examples 100 Classic C Language Examples