2.
Moving from C to C++
Cout means Console Output.
The program coded by the programmer is called the
source code. This source code is supplied to the
compiler for converting it into the machine code.
A library contains the object code of standard functions.
The object codes of all functions used in the program
have to be combined with the program written by the
programmer. In addition, some start-up code is required
to produce an executable version of the program. This
process of combining all the required object codes and
the start-up code is called linking and the final product is
called the executable code.
C++’s new features for handling I/O operations are called
streams.
<< is called as insertion or put-to operator.
>> extraction operator.
Default const(constant) variable is int.
In C++, the const qualifier can be used to indicate the
parameters that are to be treated as read-only in the
function body.
The reference variable must be initialized to some
variable only at the point of its declaration. Initialization
of reference variable after its declaration causes
compilation error. Hence, reference variables allow to
create alias (another name) of existing variables.
In C++, function prototyping is compulsory if the
definition is not placed before the function call whereas,
in C, it is optional.
To declare a function in C which has no arguments, the
keyword void is used. This is not compulsory in C++.
A function in C++ can be treated as a macro if the
keyword inline precedes its definition. It is advisable to
define functions having small function bodies as inline
functions.
The definition of several functions with the same name is
called function overloading.
It is interesting to note the way in which the C++
compiler implements function overloading. Although, the
functions share the same name in the source text, the
compiler (and hence the linker) uses different names. The
conversion of a name in the source file to an internally
used name is called name mangling.
C++ does not allow overloaded functions to only differ in
their return value.
The keyword typedef is allowed in C++, but no longer
necessary, when it is used as a prefix in enum, struct, or
union declarations.
Like C structures, C++ structures also provide a
mechanism to group together data of different types, into
one unit belonging to the same family. In addition to this,
C++ allows to associate functions as a part of a structure.
The members of a structure can be private, public or
protected.
The keywords public, private, and protected are called
access specifiers.
By default the members of a structure have public
access.
The size of a pointer in C/C++ is not fixed. It depends
upon different issues like Operating system, CPU
architecture etc. Usually it depends upon the word size of
underlying processor for example for a 32 bit computer
the pointer size can be 4 bytes for a 64 bit computer the
pointer size can be 8 bytes. So for a specific architecture
pointer size will be fixed.
The basic data types can be used with great flexibility in
assignments and expressions, due to the implicit type
conversion facility provided, whereas with the user-
defined data types, the same can be achieved through
explicit type conversion (the typecast operator).
The compiler has built-in routines for conversion of basic
data types such as char to integer, float to double, etc.
The feature of the compiler that performs data
conversion without user intervention is known as implicit
type conversion.
The compiler can be instructed explicitly to perform type
conversion using the type-conversion operators known as
typecast operator. For instance, to convert int to float,
the statement is
weight = (float) age;
where the keyword float is enclosed between braces.
Here, float enclosed between braces is the typecasting
operator. In C++, the above statement can also be
expressed in a more readable form as
weight = float( age );