2 Biginning C++ Programing
2 Biginning C++ Programing
programing
By Najibullah Rahmani
Programing
• A program is a set of instructions in proper sequence, that causes a computer to
perform a particular task.
• When learning to program in any programming languages, its best just to learn
the “rules of the game.”
// hello.cpp
// A First program in c++
#include <iostream>
using namespace std;
Int main ()
{
cout << “Hello, I am Rahmani\n”;
return 0; // indicates that the program is ended successfully
}
…continue
• Comments – a type of program documentation
// indicates that the remainder of the line is a comment
• Tells the pre-processor to include in the program the content of the I/O stream
header file called iostream.h. this allows us to use standard stream input and
output objects like cout (displays to the screen )
• As you can see we need to also code the using namespace std; statement for
now, let’s just say that this is so that we don’t have to use ugly prefixes on cout,
like std::cout.
…continue
Int main () – main function header
Every C++ program has at least one function, called main. And there is only one
main program execution begins with the first statement in main
• Expression to the right of the operator is inserted (sent ) to the cout object
(the display screen or console window )
\n newline escape sequence
• The backslash is an escape character. The character following it takes
on a different meaning e.g:
• \t = tab
• \a – alert; ring bell
• \\ - prints a backslash
• \” – prints a double quotation mark
• And …etc