Basics of C++ (Case Sensitive language)
C++ is a multi-paradigm programming language supporting:
1. Procedural Programming (Functions, structures)
2. Object-Oriented Programming (OOP) (Classes, inheritance,
polymorphism)
3. Generic Programming (Templates)
A programming language is a formal system of syntax rules and
commands used to instruct computers to perform specific tasks.
It allows humans to write code that a
computer can understand, execute, and transform into software,
apps, or systems.
• C++ is called a generic programming language because it allows writing reusable, type-
independent code using templates, enabling functions and classes to work with any data
type without rewriting logic for each type.
• C++ is called a procedural programming language because it supports the procedural
programming paradigm, where programs are structured as a sequence of functions
(procedures) that operate on data.
• C++ is called as an object-oriented programming (OOP) language because it fully supports
the four pillars of OOP:
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
#include<Header file name>
• Header files is an essential part of programming language, and they serve as a
means to include predefined standard library functions, data types, macros,
and other features in your programs.
• The #include is a pre-processor directive that instructs the compiler to process
the specified header file before the actual compilation of the source code.
• This
includes making available all the necessary data types, function definitions, and
other declarations contained within the included header file for use in your
program. It allows you to access predefined functionality and libraries to
simplify your programming tasks.
#define
• Macros in C++ are preprocessor directives.
• Preprocessor: This is a separate program that runs before the compiler. Its job
is to get the source code file ready for the actual compilation step.
• Directives: These are commands for the preprocessor. They always start with
a hash symbol # (e.g., #include, #define, #ifdef).
• A function is a “self contained block of statement”.
• The “main()” function is the entry point of every C++ program.
• It is the first function that executes when a C++ program starts, and it must
exist in every executable C++ program.
• There are two types of header files in C++:
1. Standard / Pre-existing header files
2. Non-standard / User-defined header files
Including Multiple Header Files is
an error
When you include a header file
more than once in a program, the
contents of the header file are
processed multiple times, which
can lead to errors due to
• Errors in C++ are problems that prevent your program from compiling or running correctly.
• Compile Time Error
• Occurs when the compiler cannot understand or validate the code, preventing it from creating an executable
program.
• Runtime Error
• Occurs during the execution of the program, after it has been successfully compiled. These
often cause the program to crash.
• Logical Error
• The program compiles and runs without crashing, but it produces incorrect or unexpected results due to a
mistake in the algorithm or logic.
• “cin>>” and “cout<<“ are pre-defined functions of header file <iostream>
• “cout<<“ {is an output variable} and “cin>>” {is a input variable}
• return 0 indicates successful completion.
• A namespace is just like a family name for code. It groups related code (like all the C++
Standard Library) together and prevents naming conflicts.
• The C++ Standard Library puts all its features (like cout, vector, string etc.) inside a
namespace called std (short for "standard").
The using namespace std line can be omitted and replaced with the std keyword, followed
by the :: operator for some objects: { std::cout<<”………..”}.
• Keywords in C++
• Keywords (also called reserved words) are predefined identifiers that have special meanings
in the C++ language. They cannot be used as variable names, function names, or
identifiers in your program.
• Identifiers in C++
• Identifiers are user-defined names given to variables, functions, classes, arrays, etc., in a C++
program.
• Variables in C++
• A variable in C++ is a named storage location in memory that holds a value of a specific data
type. Variables allow you to store and manipulate data in a program.
• Data Types in C++
• Data types in C++ define the type of data a variable can hold, the memory size it occupies,
and the operations that can be performed on it.
Data type and its range
#include<string>
• cin<< and getline()
The max() and min() functions are part of the C++
Standard Library
#include <cmath>
• ASCII stands for American Standard Code for Information Interchange. It is a
character encoding standard that has been a foundational element in
computing for decades.