Program Dev C++ Hello World

Program Dev C++ Hello World 3,6/5 4315 votes
  1. Program Dev C Hello World D Example
  2. Hello World C Program

// A hello world program in C. The first line in our program is a comment line. Every line that starts with two slash signs ( // ) are considered comments and will have no effect on the behavior or outcome of the program. (Words between /. and./ will also be considered as comments (old style comments)). May 17, 2017  The “Hello World” program is the first step towards learning any programming language and also one of the simplest programs you will learn. All you have to do is display the message “Hello World” on the screen. Jan 25, 2011 Create your first C Program in Dev-C (Video 1) - Duration: 5:09. Visual C 2010 Tutorial 1 - Hello World - Duration: 7:15. Sam McAnelly 259,898 views.

  • Related Questions & Answers
  • Selected Reading
C++Object Oriented ProgrammingProgramming

Program Dev C Hello World D Example

To run the hello world program, you'll have to follow the following steps −

Write a C++ program

Hello

Now that you have a compiler installed, its time to write a C++ program. Let's start with the epitome of programming example's, it, the Hello world program. We'll print hello world to the screen using C++ in this example. Create a new file called hello.cpp and write the following code to it −

Let's dissect this program.

Line 1 − We start with the #include<iostream> line which essentially tells the compiler to copy the code from the iostream file(used for managing input and output streams) and paste it in our source file. Header iostream, that allows to perform standard input and output operations, such as writing the output of this program (Hello World) to the screen. Lines beginning with a hash sign (#) are directives read and interpreted by what is known as the preprocessor.

Line 2 − A blank line: Blank lines have no effect on a program.

C++

Line 3 − We then declare a function called main with the return type of int. main() is the entry point of our program. Whenever we run a C++ program, we start with the main function and begin execution from the first line within this function and keep executing each line till we reach the end. We start a block using the curly brace({) here. This marks the beginning of main's function definition, and the closing brace (}) at line 5, marks its end. All statements between these braces are the function's body that defines what happens when main is called.

Line 4 −

This line is a C++ statement. This statement has three parts: First, std::cout, which identifies the standard console output device. Second the insertion operator << which indicates that what follows is inserted into std::cout. /c-devs-and-assembnly.html. Last, we have a sentence within quotes that we'd like printed on the screen. This will become more clear to you as we proceed in learning C++.

In short, we provide cout object with a string 'Hello worldn' to be printed to the standard output device.

Note that the statement ends with a semicolon (;). This character marks the end of the statement

Compile the Program

Now that we've written the program, we need to translate it to a language that the processor understands, ie, in binary machine code. We do this using a compiler we installed in the first step. You need to open your terminal/cmd and navigate to the location of the hello.cpp file using the cd command. Assuming you installed the GCC, you can use the following command to compile the program −

This command means that you want the g++ compiler to create an output file, hello using the source file hello.cpp.

Run the program

Now that we've written our program and compiled it, time to run it! You can run the program using −

Hello World C Program

You will get the output −