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. [Last updated : February 26, 2023]

delay(unsigned int milliseconds) function in C++

delay() function is used to hold the program's execution for given number of milliseconds, it is declared in dos.h header file.

Syntax:

void delay(unsigned int milliseconds)

Here, void is the return type of the function that means delay() will not return any value, and unsigned int milliseconds is the number of milliseconds to hold the program, delay() function accept unsigned int type of value.

Program of delay() function in C++

This program is compiled and run on TurboC3 compiler, in this program: there are delays of 1000 milliseconds (1 second) between printing of "www.", "includehelp." and ".com" then another delay to reach to getch() statement.

After that you will have to press any key to reach return 0; and program’s control will be returned (exit from program).

C++ code to demonstrate the example of delay() function

#include <iostream.h>
#include <dos.h> //for delay
#include <conio.h> //for getch()

int main()
{
	clrscr();
	
	cout<<" www.";
	delay(1000);
	cout<<"includehelp";
	delay(1000);
	cout<<".com"<<endl;
	delay(1000);
	
	getch();
	return 0;
}

Output

www.includehelp.com

There are 1 second (1000 milliseconds) delays between printing of "www.", "includehelp." and ".com"



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.