Features
Variables and Basic Data Types
In C++, we have different types of variables:
+Integral types: char , short , int , long ,
and long long +Floating-point
types: float , double , and long
double +Boolean type: bool (true or false)
To declare a variable, use the following syntax:
+ datatype variablename; +For example: int
myNumber;
Variables need to be initialized before use.
To initialize a variable, use the following syntax:
+ datatype variablename = value; +For
example: int myNumber = 5;
Strings, Vectors, Arrays
In C++, we can use arrays, vectors, and strings to
store data.
Arrays are used to store a fixed-size sequence of
elements of the same type.
To declare an array, use the following syntax:
+ datatype variablename[array_size]; +For
example: int myArray[5];
Strings are similar to arrays, but they are used to
store a sequence of characters.
To declare a string, use the following syntax:
+ string variablename; +For
, example: string myString = "Hello,
World!";
Vectors are dynamic arrays that can grow or
shrink in size.
To declare a vector, use the following syntax:
+ vector<datatype> variablename; +For
example: vector<int> myVector;
Expressions and Statements
Expressions are used to compute a value. +For
example: 2 + 2
Statements are used to control the flow of a
program. +For example: if (x > 0) { ... }
The basic statements in C++ are: +Selection
statements: if , if-else , switch +Iteration
statements: while , do-while , for +Jump
statements: break , continue , goto , return
Functions
A function is a reusable block of code that
performs a specific task.
To declare a function, use the following syntax:
+ return_type function_name(parameters)
{ ... } +For example: int add(int a, int
b) { return a + b; }
Functions can be called from other parts of the
program by using their name.
Classes and Object-oriented Programming
, In C++, classes are used to create objects that
have their own properties and behaviors.
To declare a class, use the following syntax:
+ class class_name { ... }; +For
example: class Car { ... };
Objects are instances of classes that have their
own state and behavior.
Objects are created using the new keyword.
Objects are destroyed using the delete keyword.
Input/Output Library and Concepts
In C++, the iostream library is used for
input/output operations.
To include the library, use the following syntax:
+ #include <iostream>
The std::cout object is used to print output to
the console.
The std::cin object is used to read input from
the console.
The std::endl object is used to insert a new line
character at the end of an output operation.
This is a brief introduction to the topics related to C++
Introduction and Basic Features. These topics cover the
basics of variables, data types, arrays, strings,
expressions, statements, functions, and classes, as well
as the Input/Output library and concepts. Students can
use these notes to study for exams and to learn the
basics of C++ programming.