Sunday, February 5, 2012

What is the meaning of #include ?

If a line starts with a hash, denoted by #, kit tells the compiler that a command should be sent to the C PREPROCESSOR. The C preprocessor is a program that is run before compilation takes place ( hence the name). 

Basically, when the preprocessor finds #include it looks for the file specified and replaces #include with the contents of that file. This makes the code more readable and easier to maintain if you needed to use common library functions.


Header files have the extension .h and the full filename follows from the #include directive . They contain functions that you may or may not have used in your program.

for e.g, the stdio.h file is required if you have used functions like printf() and scanf() in your program.

What is the difference between #include <...> and #include "..."

There are two ways to include a header file :

#include "stdio.h"
#include<stdio.h>

If you use the double quote marks , it  means that the directory you're currently in will be searched first , for the header file , before any other directories( mentioned in the INCLUDE_PATH ) are searched.

When you use the angled brackets , directories other than the one you're currently in , will be searched for the header file. The system dependent directories are searched. Usually this will be the default directory for header files specified in your compiler, so you'll probably be using square brackets all the time.

Sunday, January 1, 2012

What IsDangling Pointer ?

DAnging Pointer :::::::
If any pointer is pointing the memory address of any variable , but after sometime the variable is deleted  while the pointer is still pointing such memory location. Such pointer is known as dangling pointer .



  









e.g :
  

#include<stdio.h>

int *call();
void main(){

int *ptr;
ptr=call();

fflush(stdin);
printf("%d",*ptr);

}
int * call(){

int x=25;
++x;

return &x;
}


Output :::::
 Garbage Value

variable x is local variable. Its scope and lifetime is within the function call hence after returning address of x variable x became dead and pointer is still pointing ptr is still pointing to that location.

Saturday, December 24, 2011

C Program to demonstrate the use of static variables

#include<stdio.h>
#incl.ude<conio.h>
void stat();
void main()
{
    int c;
    clrscr();
     for(c=1;c<=3;c++)
     stat();
     getch();
}

void stat()
{
  static int sv=0;
  sv=sv+1;
  printf("%d\n",sv);
}

Thursday, December 15, 2011

C Program to find Hcf and Lcm Of numbers

int hcf(int n, int m) 
{ 
 
    int temp; 
    while( m > 0) 
{ 
        temp = n; 
        n = m; 
        m = temp % m; 
    } 
    return n; 
} 
 
int lcm(int n, int m) { 
    int product = n*m; 
    int hcf = hcf(n,m); 
    int lcm = product/hcf; 
    return lcm; 
} 
int main() 
{ 
    int n, m; 
    scanf("%d%d",&n,&m); 
    printf("%d\n",lcm(n,m)); 
    return 0; 
}
Mr. Denis Ritchie was found dead on October 12, 2011, at the age of 70 at his home in Berkeley Heights, New Jersey, where he lived alone. First news of his death came from his former colleague, Rob Pike. The cause and exact time of death have not been disclosed. He had been in frail health for several years following treatment for prostate cancer and heart disease. His death came a week after the death of Steve Jobs, although Ritchie's death did not receive as much media coverage.Computer historian Paul E. Ceruzzi said after his death: " Ritchie was under the radar. His name was not a household name at all, but... if you had a microscope and could look in a computer, you'd see his work everywhere inside.

!!.... Hats Off to One of the GEMS of the Computer World....!!
.....May his Soul REST IN PEACE...................

Sunday, November 27, 2011

C Program for Short Instant Quiz


#include<stdio.h>
#include<conio.h>
#include<string.h>
void prn();
int questions(char []);
int m1=0;
int m=0;
void main()
{
int i;
long ht;
char name[20];
char f1[10];
char ch[50]=" STATE TRUE OR FALSE . EACH CARRIES ONE MARK ";
clrscr();
prn();
 gotoxy(5,4);
 printf(" Student Name : ");
 scanf("%s",&name);
 gotoxy(5,6);
 printf(" HALL TICKET NUMBER : ");
 scanf("%ld",&ht);
clrscr();
prn();
gotoxy(2,5);
printf("%s",ch);
gotoxy(2,6);
for(i=0;i<strlen(ch);i++)
printf("-");
printf("\n\n");
questions(f1);
clrscr();
prn();
printf("\n\n");
printf(" STUDENT NAME  : %s",name);
printf("\n HALL-TICKET NUMBER  : %ld",ht);
printf("\n TOTAL MARKS  : %d",m);
getch();
}


void prn()
{
gotoxy(25,2);
printf(" C EXAMINATION ");
gotoxy(25,3);
printf(" ----------- ");
}




int questions(char f[])
{
printf(" 1. Structure is not a data type : ");
scanf("%s",&f[0]);
if(f[0]==102 || f[0]==70)
m++;
printf("\n");


printf(" 2. C Program is a collection of functions : ");
scanf("%s",&f[1]);
if(f[1]==116 || f[1]==80)
m++;
printf("\n");


printf(" 3. In an array we can accept more than one value of same type : ");
scanf("%s",&f[2]);
if(f[2]==116 || f[2]==84)
m++;
printf("\n");


printf(" 4. String is a character array : ");
scanf("%s",&f[3]);
if(f[3]==116 || f[3]==84)
m++;
printf("\n");


printf(" 5. Any function cannot be called from any other function  : ");
scanf("%s",&f[4]);
if(f[4]==102 || f[4]==70)
m++;
printf("\n");


printf(" 6. fflush() is a macro  : ");
scanf("%s",&f[5]);
if(f[5]==102 || f[5]==70)
m++;
printf("\n");


printf(" 7. When the file is opened in 'a+' mode modification is possible  : ");
scanf("%s",&f[6]);
if(f[6]==102 || f[6]==84)
m++;
printf("\n");


printf(" 8. Break is a reverse word  : ");
scanf("%s",&f[7]);
if(f[7]==116 || f[7]==84)
m++;
printf("\n");


printf(" 9. STRCHR finds the first occurence of a given character in a string  : ");
scanf("%s",&f[8]);
if(f[8]==116 || f[8]==84)
m++;
printf("\n");


printf(" 10. exit() fn is present in iomanip.h  : ");
scanf("%s",&f[9]);
if(f[0]==102 || f[0]==70)
m++;


return m;
}