Home / Programming / First c++ program example with code

First c++ program example with code

c program

C program with example

Today we will learn how to create a simple c++/c program to display a string on screen.

You don’t need to be a programmer to create this. This example will explain the basic principle of displaying output on screen.


(1)  C++ compiler

Download dev c++ or turbo c. Both are the IDE’s to create, compile and run your c/c++ code. (In simple words, they are the softwares that you install on your computer windows to write you c/c++ code)

Prefer to download  dev c++ as it’s UI(User-Interface) is easy to understand. Turbo c is more like old command  prompt windows.

Here is link to download Dev c++ (It’s free and open source):  click here to download

Download any version of dev c++ from this site.


#include <iostream>

void main()


cout << "Topnewsage.com!";



You will see a black screen with Topnewsage.com! printed on it.



#include <iostream>

This is the way to include a library in your code. A library is nothing special just pre-written code in an other file. You include it in on top so that you can use functions written inside isotream(Library). The “ cout<< is an output function written inside the iostream(Library). You just have to call the fucntions and use it to display any string on screen. Easy right 🙂 If it’s confusing neglect it for now, you will get it later.

void main( )

main is name of a function. It’s fix, you can not change the name of this function. The void written before main is very meaning full. Void means, main function will return nothing. Sometime we want function to return us a value at the end of it’s execution. So we replace void with int,string or any other DataType we want. Just leave this here for now.

And ( ) { } These brackets are also fix and part of function.

So completely it will become

void main ( )



That’s how you write main function.


 cout << "Topnewsage.com!";

cout is function coming from library(iostream) which is used to display output on computer screen.

so what so ever you write inside quotation mark ” some text “ , It will be displayed on screen. As we have written Topnewsage.com! you can write your name or anything to print on screen.


Task for you to try

Write a program in c++ to display your name and your friends name on screen 🙂

Happy coding.

Love, peace, respect and unity

Post your suggestion or questions below in comments, we are waiting to give you reply 🙂




About Admin

Leave a Reply

Be the First to Comment!

Notify of