Skip to main content

Data Types in C++



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

Popular posts from this blog

Variables

Variables You may have been using variables and constants in since your 3rd grade. In any programming language same concept of variables is used which covers more than half of your code. Now is you have worked in C++ or Java or Python or any other programming language you may have used variables. If you are new to programming and you have started with C# its totally OK because you don't need any degree to learn programming. Now what are the variables, to be precise variables are the empty shells which can be filled to their limit and their value can variate with the passage of time as required and manipulated on desire.  Their are few types of variables: Types Examples Integral Types stype, byte, short, ushort, int, unit, long, ulong and char Floating Point Types Floating and Double Decimal Types Decimal Boolean Types True or False value, as assigned Nullable Types Nullable Data Types Declaration Moving on we have some rules for decl...

A Path To Block Chain

 Make it easy Out of oven For a long time blockchain have been known as a theory but bitcoin changed it all. On January 3 2009 bitcoin actually came into existence. Satoshi Nakamoto found something unusual. With the concept of blockchain and mined very first block of bitcoin with reward of 50 bitbucks known as bitcoins. (ok enough with history class lets jump into fun part now). Fun part Bitcoin: Knock knock!  Currency: who is there! Bitcoin: Full stop Trolling banks and financial departments of Europe and America, Bitcoin flew from ground to paramount in no time leaving others waving. For a very long time brokers have been piercing your gold mines with hammers but Bit dude being a good sheriff said "Stop that"   Brokers: "Why" Bit dude: "I wanna take over" Brokers: "With what army" Bit dude: "This army 'anonymous transactions' " Brokers: "Fair enough" With course of few years bitcoin went through so many ups and downs...
Theory of Automata Assignment #2 Part #2 Regular Expression # 6 The set of strings over {a,b} that contain at least two a's or exactly two b's. (a+b)*(a)(b*)a(a+b)*+a*b(a*)b(a*) Regular Expression # 7 The set of strings over {a,b} that contain even length but not multiple of 3 (aa*)(aaa^) Regular Expression # 8 The language over {a,b}contains exactly one double letter.   (ε + b)(ab) ∗aa(ba) ∗(ε + b) + (ε + a)(ba) ∗ bb(ab) ∗(ε + a)