C++ 执行函数

#include <iostream>                            
using namespace std;                           
                                               
void getint()                                  
{                                              
    for(int i = 0;i<10;i++)                       
    {                                             
        for(int o=0;o<i;o++)                         
        {                                            
            cout << o;                                  
            cout << " ";                                
        }                                            
        cout << endl;                                
    }                                             
}                                              
                                               
int main()                                     
{                                              
getint();                                      
return 0;                                      
}                                              
                                               

上面这段代码是执行getint()函数

但是注意的是,C++是随行的

如果把main()函数放到getint()函数前面,就会出错

下面是错误代码:

#include <iostream>                            
using namespace std;                           
 
int main()                                     
{                                              
getint();                                      
return 0;                                      
}                                              
                                                    
void getint()                                  
{                                              
    for(int i = 0;i<10;i++)                       
    {                                             
        for(int o=0;o<i;o++)                         
        {                                            
            cout << o;                                  
            cout << " ";                                
        }                                            
        cout << endl;                                
    }                                             
}                                              
                                               
                                         

 

posted @ 2013-05-29 21:18  左眼rain  阅读(258)  评论(0编辑  收藏  举报