2. Basic knowledge of C++
● Developed by Bjarne Stroustrup
● It is an extension of the C language.
● Possible to code C++ in a "C style" or "object-
oriented style."
○ It can be coded in either way and is thus an
effective example of a hybrid language
● It is considered an intermediate-level language
★ C++ is a collection of predefined classes, which are
data types that can be instantiated multiple times
3. “Hello World” in C++
using namespace std;
#include <iostream>
// My first C++ program!
int main(void)
{
cout << "hello world!" <<
endl;
return 0;
}
Use the standard namespace
Include standard
iostream classes
A C++ comment
cout is an
instance of
ostream
operator overloading
(two different argument types!)
5. Pointers in C++
int i;
int *iPtr; // a pointer to an integer
iPtr = &i; // iPtr contains the address of I
*iPtr = 100;
…
100
456FD4
456FD4
456FD0
i
iPtr
…
variable value Address in
hex
6. C++ Blocks
● Allow a section of code to have its own local vars
whose scope is minimized.
● Such vars are stack dynamic, so they have their
storage allocated when the section is entered and
deallocated when the section is exited
C++:
for (...)
{
int index;
...
}
6
7. C++ Binding
● Binding refers to the process that is to be used for
converting functions and variables into machine
language addresses.
● C++ supports two types:
1. Static/Early Binding
2. Dynamic/Late Binding
7
8. Static/Early Binding
● In static binding, there are similar function names that
are used in many places, their references and their
positions are indicated explicitly by the compiler.
● Their ambiguities are fixed at compile time.
8
9. Static/Early Binding Example
class first // base class
{
int d;
public:
void display() {------} // base class member function
};
class second : public first // derived class
{
int k;
public:
void display() {------} // member function of derived class
}
9
10. Dynamic/Late Binding
● In the case of a few programs, it is impossible to know
which function is to be called until run time. This is
called dynamic binding.
● Dynamic binding of member functions in C++ can be
done using the virtual keyword. The member function
followed by the keyword is called a virtual function.
10
11. Dynamic/Late Binding Example
class first // base class
{
int d;
public:
virtual void display() {------} // base class member function
};
class second : public first // derived class
{
int k;
public:
virtual void display() {------} // member function of derived
class
}
11
12. C++ Static Scoping
● C++ variables are always statically scoped
● Binding of a variable can be determined by program
text and is independent of the run-time function call
stack.
● C++ doesn't use Dynamic scoping.
12
13. C++ Type checking
● Type Checking: Determining if data types make sense
for the program and follow constraints
● Static Type Checking: Type checking is done when
the program is compiled
● Dynamic Type Checking: Type checking is done at
runtime
● C++ uses static type checking
13
14. C++ Run time environment
● There isn't a universal C++ runtime
system, but in the typical OS the
primary action of the C++ runtime is
to dynamically link shared libraries to
an executable.
14