Breaking News

[ Lesson 2 ] Hello, World



YOUR FIRST C++ PROGRAM

We now introduce C++ programming, which facilitates a disciplined approach to program design. Most of the C++ programs you’ll study in this book process information and display results. In this Lesson, we present five examples that demonstrate how your programs can display messages and obtain information from the user for processing.

 The first three examples simply display messages on the screen. The next obtains two numbers from a user, calculates their sum and displays the result.  The accompanying discussion shows you how to perform arithmetic calculations and save their results for later use.

The fifth example demonstrates decision-making by showing you how to compare two numbers, then display messages based on the comparison results. We analyze each program one line at a time to help you ease your way into C++ programming.



1
2
3
4
5
6
7
#include 

// function main begins program execution
int main()
{
   std::cout << "Hello Word" << std::endl;
}

Output


Welcome to C++!


#include Preprocessor Directive 
Line 1            #include <iostream> // allows program to output data to the screen

is a preprocessor directive, which is a message to the C++ preprocessor. Lines that begin with # are processed by the preprocessor before the program is compiled. This line notifies the preprocessor to include<iostream> in the program the contents of the input/output stream header . This header must be included for any program that outputs data to the screen or inputs data from the keyboard using C++’s stream input/output

Blank Lines and White Space 
Line 2  is simply a blank line. You use blank lines, space characters and tab characters (i.e., “tabs”) to make programs easier to read. Together, these characters are known as white space. White-space characters are normally ignored by the compiler.

Comments
Line 3 begin with //, indicating that the remainder of each line is a comment. Comments do not cause the computer to perform any action when the program is run—they’re ignored by the C++ compiler and do not cause any machine-language object code to be generated.

its a document to your programs and to help other people to read and understand your code. Its always good practice  That every program/code should begin with a comment that describes the purpose of the program/code.

The main Function 
Line 5     int main() 

is a part of every C++ program. The parentheses "()" after main indicate that main is a program building block called a function. C++ programs typically consist of one or more functions and classes (as you’ll learn in the Subsequence Lessons ). Exactly one function in every program must be named main. In this Demo Example contains only one function. C++ programs begin executing at function main, even if main is not the first function in the program
Share:

No comments:

Look at

Popular Posts

Powered by Blogger.

Categories

Categories

Advertisement

Main Ad

Tags

Tags

Business

Business/featured
Find Your Destanation in Here on Us

Sheekooyin Jaceel ah

SHEEKO: Iska Illow Boodhari iyo Hodan, Qays iyo Layla, Lamaane kale oo Jacaylka Astaan u Noqday Adduunkana Taariikh ku Reebay!!

Jacaylku waa Maxay? Culumadii Hore ee Falsafaddu waxay ku wareereen in ay Qeexaan macnaha dhabta ah ee Jacalka , Plato oo kamid ah culu...

Recent Posts