Object Oriented Programming with C++-unit 1 introduction new
Object Oriented Programming with C++-unit 1 introduction new
PROGRAMMING WITH
C++
Unit 1-
Software Evolution
Since the invention of the computer, many
programming approaches have been used.
The Primary motivation in all programming
styles is the concern to handle the increasing
complexity of programs that are reliable and
maintainable.
These Programming techniques include
1. Machine Level Programming
2. Assembly Language Programming
3. High Level Programming
Machine level Language :
Machine level Language :
/* */
Compile: filename.cpp ->Alt-f9
WORKING OF C++ program
WORKING OF C++ program
Step-by-Step Guide To Compile And Execute C++ Program
3. Pre-processing:
4. Compiling:
5. Linking:
6. Generating Executable:
7. Execution:
Example C++ program
PRIMITIVE DATA TYPES
All variables use data-type during
declaration to restrict the type of data to
be stored. Therefore, we can say that
data types are used to tell the variables
the type of data it can
store. Whenever a variable is defined in
C++, the compiler allocates some
memory for that
variable based on the data type with
which it is declared. Every data type
requires a different amount of memory.
PRIMITIVE DATA TYPES
PRIMITIVE DATA TYPES
Integer: The keyword used for integer data types is int. Integers typically require 4 bytes of memory
space and range from -2147483648 to 2147483647.
Character: Character data type is used for storing characters. The keyword used for the character data
type is char. Characters typically require 1 byte of memory space and range from -128 to 127 or 0 to
255.
Boolean: Boolean data type is used for storing Boolean or logical values. A Boolean variable can store
either true or false. The keyword used for the Boolean data type is bool.
Floating Point: Floating Point data type is used for storing single-precision floating-point values or
decimal values. The keyword used for the floating-point data type is float. Float variables typically
require 4 bytes of memory space.
Double Floating Point: Double Floating Point data type is used for storing double-precision floating-
point values or decimal values. The keyword used for the double floating-point data type is double.
Double variables typically require 8 bytes of memory space.
void: Void means without any value. void data type represents a valueless entity. A void data type is used
for those function which does not return a value.
Wide Character: Wide character data type is also a character data type but this data type has a size
greater than the normal 8-bit data type. Represented by wchar_t. It is generally 2 or 4 bytes long.
sizeof() operator: sizeof() operator is used to find the number of bytes occupied by a variable/data type in
computer memory.
PRIMITIVE DATA TYPES
#include <iostream>
using namespace std;
int main()
{
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of long : " << sizeof(long) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
return 0;
}
Output
Size of char : 1
Size of int : 4
Size of long : 8
Size of float : 4
Size of double : 8
VARIABLES
Variables are containers for storing data values.
In C++, there are different types of variables
(defined with different keywords)
Declaring (Creating) Variables
To create a variable, specify the type and assign it
a value:
Syntax
type variableName = value;
Where type refers to datatype and variableName is
the name of the variable . The equal sign is used
to assign values to the variable.
VARIABLES
To create a variable that should store a
number, look at the following example:
Example