Pages

Thursday 24 January 2019

C PROGRAM TO SUBSTRACT TWO NUMBERS WITHOUT USING SUBSTRACTION SYMBOL

#include<stdio.h>

void main()
{

int a=8,b=7,r;

r = a + ~b + 1;

printf(" result is %d",r);


}

HOW TO DEBUG C PROGRAM USING - gdb

Debug c code program using gdb

A debugger is a program that runs other programs, allowing the user to exercise control over these programs, and to examine variables when problems arise.
GNU Debugger, which is also called gdb, is the most popular debugger for UNIX systems to debug C and C++ programs.

GNU Debugger helps you in getting information about the following:
  • If a core dump happened, then what statement or expression did the program crash on?
  • If an error occurs while executing a function, what line of the program contains the call to that function, and what are the parameters?
  • What are the values of program variables at a particular point during execution of the program?
  • What is the result of a particular expression in a program?

     
    GDB Debugs
  • GDB allows you to run the program up to a certain point, then stop and print out the values of certain variables at that point, or step through the program one line at a time and print out the values of each variable after executing each line
     
  • GDB uses a simple command line interface.

  • Even though GDB can help you in finding out memory leakage related bugs, but it is not a tool to detect memory leakages.
  • GDB cannot be used for programs that compile with errors and it does not help in fixing those errors.
compilation : 
step 1: The basic way of compiling garbage.c into an executable file called "garbage" is:
      gcc -o garbage garbage.c
  • If the program is compiled without errors, you can execute the program by typing "./garbage 
    gcc -g -o garbage garbage.c 
   
  • If you are interested about how the assembly code of garbage.c look like, you can also generate the assembly code by replacing the "-o garbage" option with "-S" as:   
     gcc -S garbage.c 

    Example  Program 1:
  •  // program to print n values using while loop
    #include<stdio.h>
    void main()
    {
    int i=1,n;
    printf("\n enter any value ");
    scanf("%d",&n);
    while(i<n)
    {
    printf("\n output : %d ",i);
    n++;
    }


    output :




  •  
 
 Example Program  2:
// Program to illustrate fibonocci series 
#include<stdio.h>
void main()
{
 int n,i,past=0,present=1,future;
 printf("enter any number:");
 scanf("%d",&n);
 printf("\n\t%d\t%d",past,present);
 future=past+present;
 printf("\t%d",future);
 for(i=0;i<n-3;i++)
  {
   past=present;
   present=future;
   future=past+present;
   printf("\t%d",future);
  }
}
 
output:
 
 

 



Programs in turboc3 : Files

File Handling in C File Handling concept in C language is used for store a data permanently in computer. Using this concept we can store our...