( Stroustrup ) The emphasis is on the ideas, constraints, and people that shaped the language of C++, rather than the minutiae of C language features. Key design decisions relating to language features are discussed, but the focus is on the overall design goals and practical constraints. The evolution of C++ is traced from C with Classes to the current ANSI and ISO standards work and the explosion of use, interest, commercial activity, compilers, tools, environments, and libraries. (Para 1). After a while new datatypes, operators and assignment statements and statement level control structures were added to C++ language.
C++ along with most all other programming languages provide a predefined set of primitive data types. The primitive data types are not defined in terms of other types. The most common primitive data types in C++ are integers, Booleans, and character types. Integers in C++ could also be declared as a float or a double. The float value is a four-byte value, but the double has double the precision of a float by being a sixty-four-bit value. The selection of a float or a double is important if the application needs to compute something and be extremely accurate. Boolean types in C++ are like just like they are in other programming language. This provides the programmer with the ability to use a true or false value, and only takes up one bit. However, because a single bit of memory cannot be easily retrieved, they are frequently stored as a byte. The Boolean values are also commonly used as flags or switches. Character values in defined as type “char”. A character variable in C++ occupies a single byte of memory which contains the numeric code for that character. The code is converted using a numeric coding system, most commonly the ASCII coding system.
C++ supports a set of operators for its built-in types. However, most concepts for which operators are used are not built in types, so they must be represented as user defined types. In C++ the programmer can overload a operator such as the +, -, *,/ provided at least one of the arguments is an object of some class. Defining operators for such classes sometimes allows a programmer to provide a more conventional and convenient notation for handling objects than could be achieved using only the basic functional notation. It is very important when a programmer is working in a team environment and using overloaded operators to ensure that they use very effective commenting. It is common for programmers working in a team coding environment to work on code that someone else started and it wouldn’t be easy without proper commenting to understand the overloaded operators.
Since C++ is a strongly typed programming language, which means that it requires all variables to be declared a certain data type before being used in the programming. There are times that a variable may need to be converted later on in the program. There are two types of type conversions in C++. The first is implicit type conversion, and the second is explicit type conversion. Implicit type conversions are done automatically by the compiler, and are usually performed on arithmetic operands, function arguments, function return values and initializers. Assignment statements in C++ are used to assign a value to a variable. Since C++ is a strongly typed language, the variables have to be assigned a value before they are used in the program. To assign a value to a variable the programmer uses a single equal sign. Because the single equal sign is used for the assignment statement, the programmer must use a double equal sign for arithmetic operation. The double equal sign is also used in relational expressions. Not only can the variable be assigned a single value, but it could be assigned the value of an arithmetic operation.
C++ has two different types of control structures, the selection statement and the iterative statement. There are also two different types of selection statements in C++, the if statement and the switch statement. The if statement is initialized by using the key word “if” followed by parentheses with a relational expression inside the parentheses. If there is just one operation in the if statement, then that operation can be coded directly after the parentheses. If there is more than one operation in the if statement then the block of code must be enclosed by curly brackets. The operation in the if statement is performed when the relational operator returns true. If the statement has an if, and else then the else statement comes last. The switch allows the selection of any number of statements or statement groups. The switch statement consists of a control expression, then case statements with a constant expression inside of each. At the end of the switch statement the programmer can put an optional default statement that is for unrepresented values of the control expression.
(Sebesta) A general data-based iteration statement uses a user-defined data structure and a user-defined function (the iterator) to go through the structure’s elements. The iterator is called at the beginning of each iteration, and each time it is called, the iterator returns an element from a particular data structure in some specific order. (PG 372). C++ has three different iteration statements, the while loop, the for loop, and the do while loop. A while loop in C++ is similar to an if statement in that it tests a condition and if it is true, it does something. The difference is that an if statement only does the operation one time, and the while loop does the operation until the condition becomes false. The for loop in C++ is the most commonly used loop in the language. The loop has an initialization statement, and a condition statement, it also increments or decrements each time through the loop. The initialization statement is executed one time, and the operation statement and update expression execute while the condition remains true. The do loop is used in C++ when the body of the loop must be executed at least one time before the condition of the loop is evaluated. Once the body of the loop is executed one time the condition of the loop will then be tested.
In conclusion, (Budd) the C++ I was built upon the C programming language, which was developed to be translated efficiently into fast machine code, with a minimum of housekeeping overhead. C++ builds on C by adding features for “object-oriented programming”, a programming style that enables modelling of real-world objects In the 1990s, C++ became one of the most used programming languages in the world. Its first name was C with classes, and it was then renamed to C++. (PG 11)
Budd, C. H. (2009). Big C++ 2nd Edition. John Wiley and Sons.
Sebesta, R. Concepts of programming languages (9th ed.). Boston: Addison-Wesley.
Stroustrup, B. A History of C++: 1979-1991. Murray Hill, New Jersey 07974.