Saturday, February 9, 2013

c debuggin questions 1

debugging basics....
look at the code and identify the difference between the outputs
1)
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
clrscr();
for(i++;;i++)
{
printf("%d ",i);
if(i==10)
{
break;
}
}
getch();
}       

2) #include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
clrscr();
for(i++;i++;i++)
{
printf("%d ",i);
if(i==10)
{
break;
}
}
getch();

}                

*the first program produce the output 1..10
*second program results as 2 4 6 8 10
this is because the condition(i++) itself increment the value of i in problem 2

*consider the equation 2, if we remove these statements
if(i==10)
{
break;

 the program become infinite,because of the lack of stopping condition...


 C is a programming language which is used to write computer programs and sometimes operating systems. C was created somewhere around 1969 along with the UNIX operating system (UNIX was written in C).

C is famous for being a flexible easy to learn low level language. There have been many advancements from C, C#,C++ but C still remains fairly popular. C is not an object oriented language. The object oriented version of C is C++.

Debugging is a way to remove bugs usually logical errors from programs that are currently being coded i.e. not programs which have already finished being coded and are released to the public. Debugging is mainly for developers/programmers.

When you debug a program you usually have to set a break point. A break point is a point in the program code where normal execution will stop and further instructions will be awaited by the debugger (person doing the debugging not the debugger program). The debugger can either step into statements, step over or continue normal execution. Basically when a program is being debugged the debugger presses a key and the debugger executes that statement and awaits for the debugger to press the key again to execute the next statement. This helps developers find errors in their code.


No comments:

Post a Comment