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

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)

TA ASSIGNMENT 1 PART 3

Theory of Automata Assignment #1 Part #3 Recursive Definition #11: Language of Expressions having at least one operator defined on  Σ ={+,-,*,/,a,b}  Step 1#- a+b ,a*b,a/b and a-b are in L Step 2#- If x is in L then x+x,x-x,x*x,x/x is also in L Step 3#- No words except generated above can be considered as member of Language. Recursive Definition #12: Language of string starting and ending on different alphabet defined on  Σ ={a,b} Step 1#- ab and ba are in L Step 2#- If x is in L then axb,and bxa are also in  Σ*.   Step 3#- No words except generated above can be considered as member of Language. Recursive Definition #13: Language of even numbers Step 1#- 0 and 2 are in L Step 2#- If x is in L then x+2 and x-2 is also in L .   Step 3#- No words except generated above can be considered as member of Language. Recursive Definition #14: Language of negative integers d...

Introduction

Hello azumavengers and welcome to my blog. Today we are going to introduce our blog. Introduction Introduction By Codezila  Like our Facebook page, its link is given below Codzila Facebook Page