1.who Is Written C++ ?
1.who Is Written C++ ?
Bjarne Stroustrup, a Danish computer scientist, began his work on C++'s predecessor "C with
Classes" in 1979.[6] The motivation for creating a new language originated from Stroustrup's
experience in programming for his Ph.D. thesis. Stroustrup found that Simula had features
that were very helpful for large software development, but the language was too slow for
practical use, while BCPL was fast but too low-level to be suitable for large software
development. When Stroustrup started working in AT&T Bell Labs, he had the problem of
analyzing the UNIX kernel with respect to distributed computing. Remembering his Ph.D.
experience, Stroustrup set out to enhance the C language with Simula-like features.[7] C was
chosen because it was general-purpose, fast, portable and widely used. As well as C and
Simula's influences, other languages also influenced C++, including ALGOL 68, Ada, CLU
and ML.
// 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 );
}
Example:
#include <iostream>
using namespace std;
int main ()
{
// Local variable declaration:
int a = 10;
return 0;
c. The break; statement terminates the loop(for, while and do..while loop) and switch
statement immediately when it appears.
Syntax of break
break;
In real practice, break statement is almost always used inside the body of conditional
statement(if...else) inside the loop.
}
cout<<"Sum = "<<sum;
return 0;
Syntax of continue
continue;
In practice, continue; statement is almost always used inside conditional statement.
C++ program to display integer from 1 to 10 except 6 and 9.
// C++ Program to demonstrate working of continue statement
#include <iostream>
using namespace std;
int main() {
for (int i = 1; i <= 10; ++i) {
if ( i == 6 || i == 9) {
continue;
}
cout<<i<<"\t";
}
return 0;
}
Here, key point of the while loop is that the loop might not ever run. When the
condition is tested and the result is false, the loop body will be skipped and the first
statement after the while loop will be executed.
Example:
#include <iostream>
using namespace std;
int main ()
{
// Local variable declaration:
int a = 10;
// while loop execution
while( a < 20 )
{
cout << "value of a: " << a << endl;
a++;
}
return 0;
}
Syntax
do
statement
while ( expression ) ;
The test of the termination condition is made after each execution of the loop; therefore,
a do-while loop executes one or more times, depending on the value of the termination
break, goto,
The expression must have arithmetic or pointer type. Execution proceeds as follows:
1. The statement body is executed.
2. Next, expression is evaluated. If expression is false, the do-while statement
terminates and control passes to the next statement in the program.
If expression is true (nonzero), the process is repeated, beginning with step 1.
The following
sample
demonstrates
the do-while stat
ement:
//
do_while_statement
.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
printf_s("\n%d",i+
+);
} while (i <
3);
}
F. Jump/Loop
A C++ jump statement performs an immediate
local transfer of control.
SYNTAX
break;
continue;
return [expression];
goto identifier;
G. if /else
An if statement can be followed by an optional else statement, which
executes when the boolean expression is false.
Syntax:
The syntax of an if...else statement in C++ is:
if(boolean_expression)
{
// statement(s) will execute if the boolean expression is true
}
else
{
// statement(s) will execute if the boolean expression is false
}