C data types

C data types:

A variable must have a data types with it, for example it may have data types integers, character, decimal numbers.There are few C data types. These data types are reserved words of c language. The reserved word cannot be used as a variable name.Let’s take a look different C data types. C language deal with whole numbers,real numbers, and character data. The C language provide three data types.

  1. Int
  2. Short
  3. Long

Int Data types:

Int (Integers) data types is used to store whole numbers. Integers data types has a space of 4 bytes in memory. And we mentioned as a “int ” & can’t use it as a variable name.Let’s take a sample example.

#include<iostream>
using namespace std;
main()
{
// Declare variables names then assign values 
   int x;  
   int y;
   int z;
   x = 5;
   y = 4;
   z = x + y;
 
// Get Output 

cout<<"x=";
cout<< x <<'n'; // <<'n' is use for new line 
cout<<"y=";
cout<< y <<'n'; // <<'n' is use for new line
cout<<"z=x+y=";
cout<< z <<'n'; // <<'n' is use for new line
}

Keep remember <<‘n’ use for new line. You may check the above code output below and try it yourself.

C data types

 Short data types:

As we learn above integers takes four bytes in memory. Suppose think if we store small data types in C then what will we do, that’s why in C language we will use Short data types. Short has a 2 bytes and it can store numbers in range -32768 to 32767. We can take the above example just replace int to short as following.

#include<iostream>
using namespace std;
main()
{
// Declare variables names then assign values 
   short x;  
   short y;
   short z;
   x = 5;
   y = 4;
   z = x + y;
 
// Get Output 

cout<<"x=";
cout<< x <<'n';
cout<<"y=";
cout<< y <<'n';
cout<<"z=x+y=";
cout<< z <<'n';   
}

Same output similar like before we have done it. Check the screenshot below.

C data types

Long data types:

Long data types is used to store very large whole numbers which cannot be store in int. So when we deal with large whole numbers then we use long data type in our program, It look like,
long x= 300400200

Real Numbers:

C Language provide two data types to deal with real numbers. Real numbers are also known as floating point numbers. (e.g. 1.25,56.898). Two types are as following

  1. Float data type
  2. Double data type

Float data type:

Float data type is used to store real number, float data type occupies 4 bytes in memory. Lets we take an example.

#include<iostream>
using namespace std;
main()
{
// Declare variables names then assign values 
   float x;  
   float y;
   float z;
   x = 5.34;
   y = 47.787;
   z = x + y;
 
// Get Output 
 
cout<<"x=";
cout<< x <<'n';
cout<<"y=";
cout<< y <<'n';
cout<<"z=x+y=";
cout<< z <<'n';   
}

Double data type:

Double data type is used to store large real numbers because float can’t store large real numbers. Double data types size is twice of float size. Its look like,
double x = 23409.0903943

Char data type:

 As we seen earlier we looking data types to store numbers, Now if we need to store character like x,y,z etc. C Provides facility to store character data in char data type. we may assign a char value to a variables following as.

#include<iostream>
using namespace std;
main()
{
	char y;
	y='z'; // Value must be in single quotes 
	cout<<"The character value in y=" <<'n';
	cout<<y;   
}

 Output screenshot of above example character data type.

C data types

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments