Example Data Type Program in C++

On this occasion, I will discuss data types in basic programming about the C++ language, before discussing further, let's review a little about data types, namely types that indicate what type of data you want to store by managing storage memory usage, because data can take various forms. contents such as letters, numbers, characters, etc., therefore data types are needed in programming languages. Generally data types are used to create variables that will later represent data of various data types in C++ programming.

The following are 5 data types in C++:

1. Boolean (bool)

Boolean (bool) is a data type that is used to determine true and false, this data type is the same as binary numbers, there are only two numbers, namely 0 and 1.

2. Character (char)

Character (char) is a data type for characters that is often used for data types that use letters and numbers as data.

3. Integer (int)

Integer (int) is a numeric data type that is often used for numeric data.

4. Floating Point (float)

Floating Point (float) is a numeric data type used for data in the form of fractional numbers.

5. String (string)

A string (string) is a data type that holds a character set, such as "me", "you" or "hededeh". A sentence also counts as a string data type such as "Currently learning C++ at Hededeh".

The following are 5 examples of the c++ data type program above:

1. Boolean (bool)

#include <iostream>
using namespace std;
int main(){
bool a;
a=true;
cout<<"True="<<a<<endl;
a=false;
cout<<"False="<<a<<endl;
return 0;
}

2. Character (char)

#include <iostream>
using namespace std;
int main(){
char x='A';
cout<<"Enter Class=";cin>>x;
cout<<endl<<"What You Enter Is"<<endl<<x;
return 0;
}

3. Integer (int)

#include <iostream>
using namespace std;
int main(){
int number=0, results=0;
cout<<"Enter the number bro= ";cin>>number;
results=number*2;
cout<<"Results of "<<number<<" X 2 is "<<results;
return 0;
}

4. Floating Point (float)

#include <iostream>
using namespace std;
int main (){
int S;
float Volume;
cout<<"Enter side:";
cin>>S;
Volume=S*S*S;
cout<<"Volume of Cube is:"<<Volume;
return 0;
}

5. String (string)

#include <iostream>
using namespace std;
int main(){
string message="Congratulations on doing C++ assignments, bro", sentence="";
cout<<message<<endl;
getline(cin,sentence);
cout<<sentence<<endl;
return 0;
}


That's all from the discussion about Example Data Type Programs in C++, if something is wrong in this post, maybe you can comment below, thank you ;).

Next Post Previous Post
No Comment
Add Comment
comment url