Professional Documents
Culture Documents
1. What is C ++ ?
C++ adds object-oriented features to its predecessor, C. C++ is one of
the most popular programming languages for graphical applications, such
as those that run in Microsoft Windows and Apple Macintosh
environments. C++ is named after C's increment operator. Below is an
example of a C++ program that prints Hello World!.
Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular
code lines with expressions but indications for the compilers preprocessor.
B. #include
-
Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular
code lines
with expressions but indications for the compiler's preprocessor. In this case the directive
#include
C. Iostream.h
-
Usually the compiler inserts the contents of a header file called iostream into the program.
Where it puts it depends on the system. The location of such files may be described in your
compiler's documentation. A list of standard C++ header files is in the standrat headers
reference
D. Int main ()
-
The main function is the point by where all C++ programs start their execution,
independently of its location within the source code. For that same reason, it is essential that
all C++ programs have a main function.The word main is followed in the code by a pair of
parentheses ()
E. Function
-
F. <<
-
The << operator inserts the data that follows it into the stream that preceds it .
G. Hello world\n
-
This line is a c++ statement. C++ strings are enclosed within double quotes (). The quotes
themselves are not part of the string and hence not printed. The sequence \n is used within a
string to indicate the end current line. Though the sequence is represented by two
characters , it takes up only one characters worth of memory space. Hence the sequence \n
is called the newline character.
H. \n
-
\n is the newline character, when the newline character is output to the console, the
console breaks a newline.
I. ;
-
This character is used to mark the end of the statement and in fact it must be included at the
end of all expression statements in all c++ programs (one of the mostcommon syntax errors
is indeed to forget to include some semicolon after a statement )
J. return 0;
-
The return statement causes the main function to finish . return may be followed by a return
code (in our example is followed by the return code 0), a return code of 0 for the main
function is generally interpreted as the program worked as expected without
==
>
<
!=
>=
<=
MEANING
EQUAL TO
GREATER THAN
LESS THAN
NOT EQUAL TO
GREATER THAN OR EQUAL TO
LESS THAN OR EQUAL TO
MATHEMATIC AL OPERATES
SYMBOL
1)
2)
3)
4)
5)
+
*
/
%
MEANING
ADDITION OR UNRY PLUS
SUBTRACTION OR UNARY MINUS
MULTIPLICATION
DIVISION
REMAINDER AFTER DIVISION
A. Go to
-
The goto statement is a control flow statement that causes the CPU to jump to
another spot in the code. This spot is identified through use of a statement label.
// goto_statement.cpp
#include <stdio.h>
int main()
{
int i, j;
for ( i = 0; i < 10; i++ )
{
printf_s( "Outer loop executing. i = %d\n", i );
for ( j = 0; j < 2; j++ )
{
printf_s( " Inner loop executing. j = %d\n", j );
if ( i == 3 )
goto stop;
}
}
// This message does not print:
printf_s( "Loop exited. i = %d\n", i );
stop:
printf_s( "Jumped to stop. i = %d\n", i );
}
B. W
h
i
l
e
a)
b)
c)
d)
e)
f)
g)
h)
i)
j)
// do_while_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
printf_s("\n%d",i++);
} while (i < 3);
}
C) 1
D) 2
E) 3
F) 4
G) 5
H) 6
I) 7
J) 8
K) 9
L) 10
M) 11
N) 12
O) 13
1
intnPrinted = 0;
2
3
4
7
8
nPrinted++;
10
}
11
12
13
D. While true
-
E. Do/While
-
F. Jump/Loop
-
Exucutes a sequence of statements multiple times and abbreviates the code that
manages the loop variable.
G. If/else
-