Hello azumavenger welcome
to my blog. Today we are going to talk about the data types.
Data Types in C++
Actually the data type
tells the compiler or the interpreter that in which mean the programmer intends
to use the data. That sounds confusing right? Well their is nothing to be
confused of, most of the people use the word data type and they know what it is but
they can't explain it in simple words.
Lets have an example.
A student Kutbud'deen
wrote the following code
#include<iostream>
using namespace std;
void main()
{
int var1 = 0;//integer
char var2 = '0';//character
if (var1 == 0){ cout << "var1"; }
else if (var2 == 0){ cout << "var2"; }
else { cout << "no one"; }
system("pause");
}
The output of this
code is going to be var1. Why is it so? The answer is integers can
directly be compared and used as digits, if we store digit 3 as
an integer it will behave as a typical number but if we save a character '3' here
it isn't going to act like digit 3, as it is a character with an ASCII 51. On
comparison the compiler will compare the ASCII of the character with 0 which aren't equal and
apparently the condition is false. The thing I want you to understand is that
data type is the soul of the data we use.
C++ provides built-in
as well as user defined data types.
List of Built-in data types
Types
|
Examples
|
Integral Types
|
byte, short, ushort,
int, long and char
|
Floating Point
Types
|
Floating and Double
|
Valueless Types
|
Void
|
Boolean Types
|
True or False value,
as assigned
|
Wide character
|
w_chart
|
Some websites may define void as a data type
but to me void is just a keyword and a return type that defines nothing is going to be
returned by the function and is not a data type. Void is never used to declare
any variable as it means nothing.
User defined data
types will be explained in upcoming post but just to scratch surface user
defined data types are usually structures or classes. Don't worry everything will be discussed in detail
further on so just stay tuned to this blog.
Don't forget to share
your views, follow the blog and subscribe to it. Also share
your views below.
Comments
Post a Comment