0% found this document useful (0 votes)
16 views

C++ Basics

Uploaded by

canon.snapper11
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

C++ Basics

Uploaded by

canon.snapper11
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

C++ Basics

• C++ is one of the world's most popular programming


languages
• C++ is portable and can be used to develop applications
that can be adapted to multiple platforms.
• C++ is an object-oriented programming language which
gives a clear structure to programs and allows code to be
reused, lowering development costs.
• As C++ is close to C, C# and Java, it makes it easy for
programmers to switch to C++ or vice versa.
• C++ can be found in today's operating systems, Graphical
User Interfaces, and embedded systems.
Difference between C and C++
• C++ was developed as an extension of C, and both languages
have almost the same syntax.
• The main difference between C and C++ is that C++ support
classes and objects, while C does not.
• Nearly all of C’s operators and keywords are also present in
C++ and do the same thing.
• C++ has a slightly extended grammar than C, but the basic
grammar is the same.
Syntax / Example
#include<iostream>
int main() {
cout << "Hello World!";
return 0;
}
#include <iostream> is a header file library that lets us work
with input and output objects, such as cout .Header files add
functionality to C++ programs.
int main()is called a function. Any code inside its curly
brackets {} will be executed.
Cout is an object used together with the insertion operator (<<)
to output/print text. In our example it will output "Hello
World!“
return 0 ends the main function.
C++ Data Types
1. Primitive Data Types: These data types are built-in or predefined data
types and can be used directly by the user to declare variables. example: int,
char, float, bool, etc.

2. Derived Data Types: Derived data types that are derived from the primitive
or built-in datatypes are referred to as Derived Data Types. These can be of
four types namely: Function ,Array ,Pointer ,Reference.

3. Abstract or User-Defined Data Types: Abstract or User-Defined data types


are defined by the user itself. C++ provides the following user-defined
datatypes: Class,Structure ,Union, Enumeration ,Typedef Datatype
OOPS Concepts
Object means a real word entity such as pen, chair, table etc. Object-Oriented
Programming is a methodology or paradigm to design a program using classes
and objects. It simplifies the software development and maintenance by
providing some concepts:
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
CLASSES AND OBJECTS
• Object:-Any entity that has state and behavior is known as an
object. For example: chair, pen, table, keyboard, bike etc. It can be
physical and logical.
Object is an instance of a class. All the members of the class can be
accessed through object.
• Class:- Collection of objects is called class. It is a logical entity. A
class instance must be created in order to access and use the user-
defined data type's data members and member functions. An
object's class acts as its blueprint.
When one object acquires all the properties and behaviours of parent object i.e.
known as inheritance. It provides code reusability. It is used to achieve runtime
IN H E R IT A N C E

polymorphism.
1.Sub class - Subclass or Derived Class refers to a class that receives properties from
another class.
2.Super class - The term "Base Class" or "Super Class" refers to the class from which
a subclass inherits its properties.
3.Reusability - As a result, when we wish to create a new class, but an existing class
already contains some of the code we need, we can generate our new class from the old
class thanks to inheritance. This allows us to utilize the fields and methods of the pre-
existing class.
Polymorphism
• When one task is performed by different ways i.e. known as polymorphism
• Different situations may cause an operation to behave differently. The type of
data utilized in the operation determines the behavior.

Types of Polymorphism:-

• Compile-time Polymorphism:-This type of polymorphism is achieved


by function overloading or operator overloading.

• Runtime Polymorphism:-This type of polymorphism is achieved by


Function Overriding.
ABSTRACTION & ENCAPSULATION
Hiding internal details and showing functionality is known as abstraction
In C++, we use abstract class and interface to achieve abstraction.

Binding (or wrapping) code and data together into a single unit is known as
encapsulation.

You might also like