In: Computer Science
Explain simple Vs Structured datatypes in
detail. in C++
Simple Datatypes in C++
Simple data type can only store one value at a time
1.Integral
Integral type can declare -
Integer values, Signed and Unsigned both,
ex. int,signed short int,unsigned short int
Boolean values,where true or false can be stored as 1 and 0
Characters,which is converted to int by compiler automatically
ex.char,signed char,unsigned char
2.Enum
Enumerated type is a user-defined datatype which can be assigned some limited
values.
These values are defined by the programmer at the time of declaring the enumerated
type
For ex. For gender we can use enum as it will only limit user to select from some
limited options
3.Floating
Floating types uses an IEEE-754 representation to provide an approximation
of fractional values over a wide range of magnitudes
FOllowing are floating types in c++
float
this is the smallest floating pointer in c++
double
this is larger than float,but shorter than long double
long double
is larger than double
EXAMPLE IN C++
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99; // Floating point number
double myDoubleNum = 9.98; // Floating point number
char myLetter = 'D'; // Character
bool myBoolean = true; // Boolean
OUTPUT
int: 5
float: 5.99
double: 9.98
char: D
bool: 1
Sructered Datatypes in C++
Structured data can store each dataitem as a collection of other data items
in structured data rype,the entire collection uses a single identifier name
The purpose of structured datat types is to group related data of various types for
convinient access using same identifier
1.Array
Array is a collection of fixed number of components of same type
One dimensional array is array in which components are arranged in list form
Two dimensional array is array in which components are arranged in tabular form
Example :
int num[5]
char str[10]
int twoDarray[10][10]
2.struct
A struct is a structure user defined data type in c++
A structure creates a data type that can be used to group items possibly
different types into a single type
Example :
struct Point
{
int x, y;
} p1;
3.class
class is the building block of c++ which leads it to object oriented
programming
It is a user-defined data type,which holds its own data members and members
functions,which can be accessed and used by creating an instance of that clss
Example :
class Student{
int studentId = 1;
int getStudentId()
{
return studentId;
}
}