3. C++
• C++ is a general-purpose programing
language.
• C++ is used to create computer programs
Anything from application , Music players and
even video gamest.
3
i C++ was derived from C, and is largely based on it
4. C++ is a:
General purpose programing language
Movie making program
Client-side scripting language
4
5. C++ is a:
General purpose programing language
Movie making program
Client-side scripting language
5
6. main
Source code
1. // my first program in C++
2. # include <iostream>
3.
4. int main ()
5. {
6. std::cout<<“Hello Word!”;
7. }
Output
Hello Word!
6
Program execution begin with the main function ,Int main().
7. main
• Curly brackets { } indicate the beginning and
end of function, which can also be called the
function’s body.
• The information inside the brackets indicates
what the function does when executed.
7
i
The entry point of every C++ program is main(),
irrespective of what the program does.
8. What is the starting point for a computer program?
main function
from <iostream>
first line
8
9. What is the starting point for a computer program?
main function
from <iostream>
first line
9
10. Your first C++ program
1. # include <iostream>
2.
3. int main ()
4. {
5. std::cout<<“Hello Word!”;
6. }
Hello Word!
10
The next line, Cout<<“Hello world !”; result in the display of “hello world “
to the screen.
11. Your first C++ program
• In C++ Stream are used to perform input and out put operations.
• In the most program environments, the standard default output
destination is the screen .
• in C++ cout is the stream object used to access it.
• Cout is used in combination with the insertion operator
• Writ the insertion operator as << to insert the data that comes after it
into the stream that comes before.
11
i
In C++ , the semicolon is used to terminate a statement.
Each statement must end with a semicolon . It indicate the
end of one logical expression.
12. Each instruction must end with a
dot ( . )
Comma ( , )
Colon ( : )
Semicolon ( ; )
12
13. Each instruction must end with a
dot ( . )
Comma ( , )
Colon ( : )
Semicolon ( ; )
13
14. Statement
• A block is a set of logical connected
statements, surrounded by opening and closing
curly braces
1. {
2. cout<<“Hello Word!”;
return 0;
3. }
14
i
You can have multiple statement on a single line, as long as
you remember to end each statement with a semicolon .
Failing to do so will result in an error
15. Components of a C++ program
You can add multiple insertion operation after
cout
1. {
2. cout<<“This” << “awesome!”;
return 0;
3. }
15
16. New Line
The cout operator does not insert a line break at
the end of the output.
Own a way to print two line is to use the endl
manipulator , which will put a line break
1. {
2. cout<<“Hello” << endl ;
3.cout<< “My name is Ahmad!”;
return 0;
4. } 16
17. What should be used to move to an new line
start
#include
endl
next line
17
18. New Lines
The new line character n can be used as an
alternative to endl.
The backslash () is called an escape character
and indicate a “special” character.
1. {
2. cout<<“welcome n” ;
3.cout<< “My name is Ahmad!”;
return 0;
4. } 18
19. What is symbol for moving to a new line( alternative
to the endl)
a
n
b
19
20. What is symbol for moving to a new line( alternative
to the endl)
a
n
b
20
21. Comments
Comments are explanatory statement that you
can include in the C++ code to explain what the
code is doing.
The compiler ignores everything that appears int
the comment.so none of that information shows in
the result.
A comment beginning with two slashes (//) is
called single-line comment.
The slashes tell the compiler to ignore everything
that follows.
until the end of the line
21
22. Comment
1. # include <iostream>
2. using namespace std;
3. //std is declaration region
4. int main ()
5. {
6. //pring “hello world”
7. cout<<“Hello Word!”;
8. return 0;
9. }
Hello Word!
22
When the following code is compiled , it will ignore the
// prints “ hello world” statement and will produce the following result.
23. Which choice indicate a signal-line comment
// single line comment
** single line comment
##single the comment
23
24. Which choice indicate a signal-line comment
// single line comment
** single line comment
##single the comment
24
25. Multi-Line Comments
Comment that require multiple lines begin with
/* and end with */
You can place them on the same line or insert
one or more lines between them.
/* This is a comment */
/* C++ comments can
Span multiple lines
*/
25
26. Create a block comment ( multiline comment) in C+
+
This is a block /multiline
Comment in C++
26
27. Create a block comment ( multiline comment) in C+
+
This is a block /multiline
Comment in C++
27
/*
*/
28. Which of the following in true
Comments are ignored by the compiler
Comments are used to confuse programmers
single line comments starts with an *
28
29. Which of the following in true
Comments are ignored by the compiler
Comments are used to confuse programmers
single line comments starts with an *
29