Delay In Dev C++

C program to demonstrate example of delay function. Dos.h delay function in C: Here, we will learn about the delay function of dos.h header file in C through a simple example/program. Delay function is used to hold the program's execution for given number of milliseconds, it is declared in dos.h header file. May 16, 2018  When printing it out, you can see the first line in the program is 3 seconds before the second line. The reason for this is the sleep function that is on line 11. As you can see, I entered 3000 milliseconds as the parameter which is 3 seconds. Well, there you have it, the sleep function in C.

  1. Delay No Dev C++
  2. How To Use Delay In Dev C++
  3. Delay In Dev C++
  4. Timed Delay In C

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

Online compiler dev c++ OnlineGDB is online IDE with C compiler. Quick and easy way to compiler c program online. It supports g compiler for c.

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 which is not a part of standard C library.

Delay in C program

If you don't wish to use delay function then you can use loops to produce delay in a C program.

#include<stdio.h>

Delay No Dev C++

int main()
{
int c, d;
for(c =1; c <=32767; c++)
for(d =1; d <=32767; d++)
{}
return0;
}

We have not written any statement in the loop body. You may write some statements that doesn't affect logic of the program.

How To Use Delay In Dev C++

C programming code for delay

#include<stdio.h>
#include<stdlib.h>

main()
{
printf('This C program will exit in 10 seconds.n');

Delay In Dev C++

delay(10000);

return0;
}

Timed Delay In C

This C program exits in ten seconds, after the printf function is executed the program waits for 10000 milliseconds or 10 seconds and then it terminates.