如何调试程序(含使用断点)


    

CodeBlocks调试功能快捷教程

分类: C++ 13722人阅读 评论(25) 收藏 举报

  在程序设计中,单步调试能够跟踪程序的执行流程。跟踪过程中,还可以观察变量的变化,从而发现其中存在的问题。单步执行除了可以帮助我们发现设计的程序中存在的问题,对于初学者,还可以帮助我们理解语言的机制。

  所以,对于初学者,掌握所用的集成开发环境的一般用法,是一件非常重要的事情。

  由于其重要性,再引用中国的一句古话“工欲善其事,必先利其器”,单步调试就是程序设计者最重要的工具之一,这种工具的形态是软件。程序员用软件当工具,正常得不得了。

  本文介绍CodeBlock的调试功能。因为面向初学者,高手请绕行。到资源中下载,请点链接:http://download.youkuaiyun.com/detail/sxhelijian/6541685

  (相关链接——我写的VC++中调试功能:VC++6.0调试工具使用初步








示例代码:
  1. #include <iostream>  
  2. using namespace std;  
  3. const double pi=3.1415926;  
  4. int main( )  
  5. {  
  6.     float r,a;  
  7.     cout<<"输入半径:"<<endl;  
  8.     cin>>r;  
  9.     a=pi*r*r;  
  10.     cout<<"输出面积:";  
  11.     cout<<a<<endl;  
  12.     return 0;  
  13. }  
  14.   
  15. float volume(float h,float r)  
  16. {  
  17.     return pi*r*r*h;  
  18. }  
#include <iostream>
using namespace std;
const double pi=3.1415926;
int main( )
{
    float r,a;
    cout<<"输入半径:"<<endl;
    cin>>r;
    a=pi*r*r;
    cout<<"输出面积:";
    cout<<a<<endl;
    return 0;
}

float volume(float h,float r)
{
    return pi*r*r*h;
}






实践代码:

  1. #include <iostream>  
  2. using namespace std;  
  3. const double pi=3.1415926;  
  4. int main( )  
  5. {  
  6.     int a;  
  7.     cout<<"请输入一个数:"<<endl;  
  8.     cin>>a;  
  9.     if(a = 2)  
  10.         cout<<"你2了。";  
  11.     else  
  12.         cout<<"你不2。";  
  13.     return 0;  
  14. }  
#include <iostream>
using namespace std;
const double pi=3.1415926;
int main( )
{
    int a;
    cout<<"请输入一个数:"<<endl;
    cin>>a;
    if(a = 2)
        cout<<"你2了。";
    else
        cout<<"你不2。";
    return 0;
}






示例代码:
  1. #include <iostream>  
  2. using namespace std;  
  3. const double pi=3.1415926;  
  4. float area(float r);  
  5. int main( )  
  6. {  
  7.     float r1,a1;  
  8.     cin>>r1;  
  9.     a1=area(r1);  
  10.     cout<<a1<<endl;  
  11.     return 0;  
  12. }  
  13. float area(float r)  
  14. {  
  15.     float a;  
  16.     a = pi*r*r;  
  17.     return a;  
  18. }  
#include <iostream>
using namespace std;
const double pi=3.1415926;
float area(float r);
int main( )
{
    float r1,a1;
    cin>>r1;
    a1=area(r1);
    cout<<a1<<endl;
    return 0;
}
float area(float r)
{
    float a;
    a = pi*r*r;
    return a;
}





实践代码:
  1. #include <iostream>  
  2. using namespace std;  
  3. float max(float x, float y);  
  4. int main ()  
  5. {  
  6.     float a,b,c;  
  7.     cin>>a>>b;  
  8.     c=max(a, b) ;  
  9.     cout<<"The max is "<<c<<endl;  
  10.     return 0;  
  11. }  
  12. float max(float x, float y)  
  13. {  
  14.     float z;  
  15.     z=(x<y)? x : y ;  
  16.     return  z;  
  17. }  
#include <iostream>
using namespace std;
float max(float x, float y);
int main ()
{
    float a,b,c;
    cin>>a>>b;
    c=max(a, b) ;
    cout<<"The max is "<<c<<endl;
    return 0;
}
float max(float x, float y)
{
    float z;
    z=(x<y)? x : y ;
    return  z;
}




示例代码:

  1. #include<iostream>  
  2. #include<cmath>  
  3. using namespace std;  
  4. int max(int,int);  
  5. int main( )  
  6. {  
  7.     int m,a,b;  
  8.     a=100;  
  9.     b=200;  
  10.     m=max(a,b);  
  11.     cout<<"最大:"<<m<<endl;  
  12.     return 0;  
  13. }  
  14. int max(int x,int y)  
  15. {  
  16.     int z;  
  17.     if(x>y)  
  18.         z=x;  
  19.     else  
  20.         z=y;  
  21.     return z;  
  22. }  
#include<iostream>
#include<cmath>
using namespace std;
int max(int,int);
int main( )
{
    int m,a,b;
    a=100;
    b=200;
    m=max(a,b);
    cout<<"最大:"<<m<<endl;
    return 0;
}
int max(int x,int y)
{
    int z;
    if(x>y)
        z=x;
    else
        z=y;
    return z;
}




实践代码:
  1. #include <iostream>  
  2. using namespace std;  
  3. float max(float x, float y);  
  4. int main ()  
  5. {  
  6.     float a,b,c;  
  7.     cin>>a>>b;  
  8.     c=max(a, b) ;  
  9.     cout<<"The max is "<<c<<endl;  
  10.     return 0;  
  11. }  
  12. float max(float x, float y)  
  13. {  
  14.     float z;  
  15.     z=(x<y)? x : y ;  
  16.     return  z;  
  17. }  
#include <iostream>
using namespace std;
float max(float x, float y);
int main ()
{
    float a,b,c;
    cin>>a>>b;
    c=max(a, b) ;
    cout<<"The max is "<<c<<endl;
    return 0;
}
float max(float x, float y)
{
    float z;
    z=(x<y)? x : y ;
    return  z;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值