3. 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
3
4. 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!
4
When the following code is compiled , it will ignore the
// prints “ hello world” statement and will produce the following result.
5. Which choice indicate a signal-line comment
// single line comment
** single line comment
##single the comment
5
6. Which choice indicate a signal-line comment
// single line comment
** single line comment
##single the comment
6
7. 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
*/
7
8. Create a block comment ( multiline comment) in C+
+
This is a block /multiline
Comment in C++
8
9. Create a block comment ( multiline comment) in C+
+
This is a block /multiline
Comment in C++
9
/*
*/
10. Which of the following in true
Comments are ignored by the compiler
Comments are used to confuse programmers
single line comments starts with an *
10
11. Which of the following in true
Comments are ignored by the compiler
Comments are used to confuse programmers
single line comments starts with an *
11
12. Variables
Creating a variable reserves a memory location.
Space in memory for storing values . The
compiler that you provide a data type for each
variable you declare.
C++ offer a rich assortment of built-in as well as
user defined data type.
Integer , a built-in type , represents a whole
number value. Define Integer using the keyword
int C++ requires that you specify the type and
identifier for each variable defined
12
13. Variables
An identifier is a name for a variable, function
class,module,or any other user-defined item.
An identifier stars with a letter ( A-Z or a-z) or an
underscore ( _ ) followed by additional
letters,underscores,and digits ( 0 – 9 )
For example
Define a variable called myVariable that can hold
integer values as follows.
Int myVariable= 10;
13
14. What is the data type name for integer?
Double
integer
Int
number
14
15. Variables
Now , Lets assign a values to the variable and
print it.
1.# include <iostream>
2. using namespace std;
3. int main () { 10
4.Int myVariable = 10 ;
5. cout<<“Hello Word!”;
6.Return 0;
7. }
// output 10 15
16. What is the data type name for integer?
Double
integer
Int
number
16
i The C++ programing language is Case-Sensitive , So
myVariable and myvaraible are tow deferent .
17. Variables
Define all variables with a name and a data type
before using them in a program. In cases in which
you have multipl3e variables of the same type.it’s
possible to define them in one declaration
,separating them with commas
Int a , b ;
//define two variable of type int.
17
18. Variables
A variable can be assigned a value , and can be
used to perform operations.
For Example , we can create an additional
variable called sum, and two variable together.
int a =10;
int b = 40 ;
int sum = a + b;
// Now sum equals 50.
18
i Use the + operator to add two numbers.
19. Variables
Let’s create a program to calculate and print the
sum of two integer.
1. # include <iostream>
2. using namespace std;
3. int main () {
4.int a =10;
5.int b = 40 ;
6.int sum = a + b;
cout << sum ;
7.Return 0;
8.// output 42
19
i
Always keep in mind that all variables must be defined with a
name and a data type before they can be used.
20. Which two statement are true for variable in C++?
variable do not have name
variable must be declared before their use.
Variable are pre-processor directive
Variable must have a data type
20
21. Which two statement are true for variable in C++?
variable do not have name
variable must be declared before their use.
Variable are pre-processor directive
Variable must have a data type
21