在程序設計中,單步調試能夠跟蹤程序的執行流程。跟蹤過程中,還可以觀察變量的變化,從而發現其中存在的問題。單步執行除了可以幫助我們發現設計的程序中存在的問題,對於初學者,還可以幫助我們理解語言的機制。
所以,對於初學者,掌握所用的集成開發環境的一般用法,是一件非常重要的事情。
由於其重要性,再引用中國的一句古話“工欲善其事,必先利其器”,單步調試就是程序設計者最重要的工具之一,這種工具的形態是軟件。程序員用軟件當工具,正常得不得了。
本文介紹CodeBlock的調試功能。因為面向初學者,高手請繞行。到資源中下載,請點鏈接:http://download.csdn.net/detail/sxhelijian/6541685
(相關鏈接——我寫的VC++中調試功能:VC++6.0調試工具使用初步)







示例代碼:
- #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;
- }




實踐代碼:
- #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;
- }



示例代碼:
- #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;
- }



實踐代碼:
- #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;
- }



示例代碼:
- #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;
- }


實踐代碼:
- #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;
- }


