Introduction to gdb (Gnu Debugger)

Write a sample C program with errors for debugging purpose

To learn C program debugging, let us create the following C program that calculates and prints the factorial of a number. However, this C program contains some errors in it for our debugging purpose.

$ vim factorial.c
# include <stdio.h>

int main()
	int i, num, j;
	printf ("Enter the number: ");
	scanf ("%d", &num );

	for (i=1; i<num; i++)

	printf("The factorial of %d is %d\n",num,j);
$ cc factorial.c

$ ./a.out
Enter the number: 3
The factorial of 3 is 12548672

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s