Unlocking the Future of AI Agents with Large Language Models
Data types
1. Data
Types
A P r e s e n t a t i o n O n C + + P r o g r a m m i n g
2. What Is C++
Programming
C++ Is An Object Oriented Programming (OOP)
Language,
Developed By Bjarne Stroustrup,
Is An Extension Of C Language
Possible To Code C++ In A "C Style" Or "Object-
oriented Style.“
Can Be Coded In Either Way And Is Thus An Effective
Example Of A Hybrid Language.
It Is Pronounced "C-plus-plus."
3. What Is C++
Programming
C++ Is A General Purpose Object Oriented
Programming Language.
It Is Considered To Be An Intermediate Level
Language,
It Encapsulates Both High And Low Level Language
Features.
The Language Was Called 'C With Classes’ As It Had
All Properties Of C
4. Data Types
A Data Type can be Classified:
Identifying One Of Various Types Of Data,
Such As Real, Integer Or Boolean,
Determines The Possible Values For That Type,
Operations Can Be Done On Values Of That Type,
The Meaning Of The Data,
The Way Values Of That Type Can Be Stored.
5. While doing programming in any programming language, you
need to use various variables to store various information.
Variables are nothing but reserved memory locations to store
values.
This means that when you create a variable you reserve
some space in memory.
You may like to store information of various data types like
character, wide character, integer, floating point, double
floating point, Boolean etc.
Based on the data type of a variable, the operating system
allocates memory and decides what can be stored in the
reserved memory.
8. Primitive Data Types
Primitive data types are predefined types of data, which
are supported by the programming language.
For example , integer, character, and string are all
primitive data types.
Programmers can use these data types when creating
variables in their programs.
For example, a programmer may create a variable
called "lastname" and define it as a string data type.
The variable will then store data as a string of
characters.
9. Char
character
C++ offers a predefined data type that is one byte in
size, which can hold exactly one character
Such as ‘a’ or ‘A’. To declare a variable of type char, we
have
Char ch;
Suppose we want to store a character value ‘a’, in a
char data type ch, it is enclosed within a single quote.
Ch = ‘a’;
Only a single character can be stored in a variable of
type char.
10. Int
integer
On most machines the size of int type is 2 bytes.
C++ defines this type as consisting of the values
ranging from -32768 to 32767.
This range is for the small integer. If long integer is
needed the type long or long int can be used.
The range of long int is too big that is from-2147483648
to 2147483647, which occupies 4 bytes in memory.
11. Float
C++ defines the data type float as representing
numbers that have fractional part.
For example,12.55 as opposed to integers which have
no fractional part.
Floating point variables can either be small or large.
A variable with type float occupies 4 bytes in size and
can hold numbers from 10-308 to 10—308 with about
15 digits of precision.
There is a long double, also available, that can hold
numbers from 10--4932 to 10-4932.
12. Boolean
Bool
Unlike ‘C’, it is an additional data type for representing
a Boolean value.
A variable associated with a bool data type may be
assigned an integer value 1 to the literal true or a
value 0 to the literal false.
13. Derived Data Types
Data types that are derived from the built-in data types
are known as derived data types.
The various derived data types provided by C++ are
arrays, junctions, references and pointers.
14. Array
Series Of Elements Of The Same Type Placed In
Contiguous Memory Locations
Can Be Individually Referenced By Adding An Index To
A Unique Identifier.
For Example, Five Values Of Type Int Can Be Declared
As An Array Without Having To Declare 5 Different
Variables (Each With Its Own Identifier).
15. Pointer
For a C++ program, the memory of a computer is like a
succession of memory cells, each one byte in size, and
each with a unique address.
These single-byte memory cells are ordered in a way
that allows data representations larger than one byte to
occupy memory cells that have consecutive addresses.
This way, each cell can be easily located in the memory
by means of its unique address.
For example, the memory cell with the
address 1776 always follows immediately after the cell
with address 1775 and precedes the one with 1777, and
is exactly one thousand cells after 776 and exactly one
thousand cells before 2776.
16. Function
Functions allow to structure programs in segments of
code to perform individual tasks .
In C++, a function is a group of statements that is given
a name, and which can be called from some point of the
program.
The most common syntax to define a function is:
type name ( parameter1, parameter2, ...) { statements
Where:
- type is the type of the value returned by the function.
- name is the identifier by which the function can be
called.
- parameters (as many as needed): Each parameter
consists of a type followed by an identifier, with each
parameter being separated from the next by a comma
18. Enumerated
An enumerated type (also called an enumeration)
is a data type where every possible value is defined as
a symbolic constant (called an enumerator).
Enumerations are declared via the enum keyword.
19. Structure
Structure is another user defined data type which
allows you to combine data items of different kinds.
Structures are used to represent a record, suppose you
want to keep track of your books in a library. You might
want to track the following attributes about each book:
Title
Author
Subject
Book ID
20. Union
Unions allow one portion of memory to be accessed as
different data types.
Its Declaration and use is similar to the one of
structures, but its functionality is totally different.
21. Basic Program Based On float
#inc lude< ios tream.h >
#inc lude< c onio.h>
void main( )
{
Float a,b,c ,d
a= 7
b= 6
c = 9
d = a+ b+c
c out< <n;
getc h ( ) ;
}
22. Basic Program Based On Array
#include<iostream.h>
#include<conio.h>
void main()
{
intX[5]={2,5,8,1,6};
floatY[5]={1.2,3.1,4.2,5.1,6.1};
int i;
cout<<“ array x”;
for(i=0;i<5;i++)
{
cout<<“display of x[“<<i<<”]<<x[i];
cout<<‘array of y”;
for(i=0;i<5;i++)
cout<<“Display of array
Y[“<<i<<”]<<Y[i];
}
getch();
}
23. Basic Program Based On enum
#include <iostream>
using namespace std;
main()
{
enum
{
Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
} day;
day = Wednesday;
if(day == saturday || day == sunday)
cout << "Day is a weekend day" << endl;
else if(day == wednesday)
cout << "Day is hump day - middle of the work week" << endl;
}