delay function in c

Delay in c: delay function is used to suspend execution of a program for a particular time.

Declaration :- void delay(unsigned int);

Here unsigned int is the number of milliseconds ( remember 1 second = 1000 milliseconds ). To use delay function in your program you should include the dos.h header file.

C programming code for delay
#include<stdio.h>
#include<stdlib.h>

main()
{
    printf("This c program will exit in 10 seconds.\n");       

    delay(10000);                        

    return 0;
}
Above c program exits in ten seconds, after the printf function is executed the program waits for 10000 milliseconds or 10 seconds and then program termination occurs.

Delay in c program
: If you don't wish to use delay function then you can use loops to produce delay in c program.

#include<stdio.h>

main()
{
   int c = 1, d = 1;

   for ( c = 1 ; c <= 32767 ; c++ )
       for ( d = 1 ; d <= 32767 ; d++ )
       {}

   return 0;
}
We don't write any statement in the loop body.

Comments

Popular posts from this blog

Operators And Separators In C Language Operators in C Language:

Difference between asterisk and ampersand operators in c