Professional Documents
Culture Documents
(Danish: born 30 December 1950) is a Danish computer scientist, most notable for the
creation and development of the widely used C++ programming language. He is a
Distinguished Research Professor and holds the College of Engineering Chair in Computer
Science at Texas A&M University,]a visiting professor at Columbia University, and works
at Morgan Stanley.
Education
troustrup has a master's degree in mathematics and computer science (1975) from Aarhus
University, Denmark, and a Ph.D. in computer science (1979) from the University of
Cambridge, England.[5] His thesis advisor in Cambridge was David Wheeler
Career
Stroustrup began developing C++ in 1978 (then called "C with Classes"), and, in his own
words, "invented C++, wrote its early definitions, and produced its first implementation...
chose and formulated the design criteria for C++, designed all its major facilities, and was
responsible for the processing of extension proposals in the C++ standards
committee. Stroustrup also wrote a textbook for the language, The C++ Programming
Language.
Stroustrup was the head of AT&T Bell Labs' Large-scale Programming Research
department, from its creation until late 2002. Stroustrup was elected member of the National
Academy of Engineering in 2004. He is a Fellow of the ACM (1994) and an IEEE Fellow. He
works at Texas A&M University as a Distinguished Professor where he holds the College of
Engineering Endowed Chair in Computer Science. He is also a visiting faculty in Computer
Science Department at Columbia University.ITMO University noble doctor since 2013
In 2015, he was made a Fellow of the Computer History Museum for his invention of the C+
+ programming language.
Publications
Stroustrup has written or co-written a number of publications[17][18][19] including the following
books.
Programming: Principles and Practice Using C++ by Bjarne Stroustrup AddisonWesley Professional; 1st edition (29 December 2008); ISBN 0-321-54372-6.
The C++ Programming Language by Bjarne Stroustrup Addison-Wesley Pub Co; 4th
edition (23 May 2013); ISBN 0-321-563840.
The Design and Evolution of C++ by Bjarne Stroustrup Addison-Wesley Pub Co; 1st
edition (29 March 1994); ISBN 0-201-54330-3.
The Annotated C++ Reference Manual by Margaret A. Ellis & Bjarne Stroustrup
Addison-Wesley Pub Co; (1 January 1990); ISBN 0-201-51459-1
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;
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
while (true) {
// test expression is always true
cout<<"Enter a number: ";
cin>>number;
if (number != 0.0) {
sum += number;
}
else {
break; // terminating the loop if number equals to 0.0
}
}
cout<<"Sum = "<<sum;
return 0;
}
Output
Enter a number: 4
Enter a number: 3.4
Enter a number: 6.7
Enter a number: -4.5
Enter a number: 0
Sum = 9.6
are used to perform repetitive task until test expression is false but sometimes it is
desirable to skip some statement/s inside loop or terminate the loop immediately with
7 8
10
D ) While True
I'm curious about using a while statement with a truecondition. What is the
advantage of using a while(true) statement with break to exit the while
statement over something like a for loop? I guess I'm just curious when a good
time to use this technique would be? I saw it demonstrated in a quick sort
algorithm at school today and was just curious about it. Insight?
Edit: In my Java course we were taught that using break was a bad habit.
Seems like this code violates something or is it acceptable to use break often in
C++.
1 #include <iostream>
2 using namespace std;
3
4 int main (int argc, char * const argv[]) {
5
6
int counter = 9;
7
8
while (true) {
9
10
cout << "Counter: " << counter << endl;;
11
counter--;
12
13
14
15
16
17
18
19
20 }
21
if (counter == 0) {
break;
}
}
return 0;
E ) Do / While
Executes a statement repeatedly until the specified termination condition
evaluates to zero
Syntax
do
statement
while ( expression ) ;
F ) Jump / Loop
A simple C++ statement is each of the individual instructions of a program, like
the variable declarations and expressions seen in previous sections. They
always end with a semicolon (;), and are executed in the same order in which
they appear in a program.
But programs are not limited to a linear sequence of statements. During its
process, a program may repeat segments of code, or take decisions and
bifurcate. For that purpose, C++ provides flow control statements that serve to
specify what has to be done by our program, when, and under which
circumstances.
Many of the flow control statements explained in this section require a generic
(sub)statement as part of its syntax. This statement may either be a simple C+
+ statement, -such as a single instruction, terminated with a semicolon (;) - or
a compound statement. A compound statement is a group of statements (each
of them terminated by its own semicolon), but all grouped together in a block,
enclosed in curly braces: {}:
{ statement1; statement2; statement3; }
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
}
Example:
#include <iostream>
using namespace std;
int main ()
{
// local variable declaration:
int a = 100;
// check the boolean condition
if( a < 20 )
{
// if condition is true then print the following
cout << "a is less than 20;" << endl;
}
else
{
// if condition is false then print the following
cout << "a is not less than 20;" << endl;
}
cout << "value of a is : " << a << endl;
return 0;
}
When the above code is compiled and executed, it produces the following
result:
a is not less than 20;
value of a is : 100
An if can have zero or one else's and it must come after any else if's.
An if can have zero to many else if's and they must come before the else.
Syntax:
The syntax of an if...else if...else statement in C++ is:
if(boolean_expression 1)
{
Example:
#include <iostream>
return 0;
}
When the above code is compiled and executed, it produces the following
result:
Value of a is not matching
Exact value of a is : 100