DataTypes in C

Variables are basic and important concept before Datatypes, if you have not been gone through variables, please click here to know about variables in C. We know that variable should be declared before using it. Data types are the keywords, which are used for assigning a type to the variable.

The size of variable and constant are identified by data type.Data types are classified into two types.

Fundamental data type:

  • integer data type.
  • floating data type.
  • character data type.

Derived Data type:

  • Arrays
  • Structures
  • Enumeration.
  • Pointers.

syntax:
data_type variable_name;

example:
int a;
here, int is a  data type
a is the variable name

Integer data type:

“int” is a keyword used to refer integer data type.it allows a variable to store numeric values. int allocates 2 bytes of memory for that variable.

int a = 1;

It can store a value from -32768 to 32767.

long int data type allocates 4 bytes in memory,it can store value from -2,147,483,648 to +2,147,483,647.

Floating data type:

floating data type consists of a float and double.

“float” is a key word used to refer float data type. It allows a variable to store decimal numbers. Float allocates 4 bytes of memory for that variable.

float a = 1.5;

the range for the double data type is from 1E-37 to 1E+37.

Character data type:

“char” keyword is used to refer character data type, it allows to store only one character, Default storage size for character data type is 1 byte.

char variable_name= ‘A’;

note:sizeof() used to find the memory space for all data types.

Qualifiers:

Qualifiers alter the meaning of fundamental data types.There are three Qualifiers in C

sign Qualifiers:

Whether a variable can hold only positive values or both, can be specified by sign qualifiers.

signed‘ and ‘unsigned‘ are sign QualThe default is signed Qualifier.

example: unsigned int a;

here variable a can store only positive numbers.

size Qualifier:

These keywords are to alter the size of fundamental keywords. ‘long’ and ‘short’ are two keywords.

The size of ‘int’ variable is 2 bytes, if we want to store large values, ‘we will use ‘long’ (like long int a )

short can be used for the smaller size of a variable.

Constant Qualifiers:

if a variable has const as a prefix , then the value of that variable can not be changed.

const int a = 10;

Enumerator data type:

Enumeration data type consists of named integer constants as a list.
It starts with 0 (zero) by default and value is incremented by 1 for the sequential identifiers in the list.
Enum syntax in C:
enum identifier {

enumerator-list

};

example:
enum fruits
{
apple,
orange,
Mango
};
apple = 0,orange =1,Mango =2.

Next chapters will give you more concepts about decision-making, where we can apply data types in examples

Comments

comments

12 Replies to “DataTypes in C”

  1. Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your weblog? My blog is in the very same area of interest as yours and my users would definitely benefit from a lot of the information you present here. Please let me know if this okay with you. Cheers!|

    1. its good to hear that. yes please link my blog on yours. and i will look at yours and add the links of you here as well where it fits

  2. Admiring the dedication you put into your blog and detailed information you offer. It’s nice to come across a blog every once in a while that isn’t the same old rehashed material. Excellent read! I’ve bookmarked your site and I’m including your RSS feeds to my Google account.

  3. I know this if off topic but I’m looking into starting my own blog and was wondering what all is needed to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web smart so I’m not 100 sure. Any recommendations or advice would be greatly appreciated. Kudos

  4. I simply want to mention I’m all new to weblog and certainly liked this blog site. More than likely I’m want to bookmark your blog post . You really have perfect article content. With thanks for sharing with us your web page.

  5. Thanks for one’s marvelous posting! I really enjoyed reading it, you happen to be a great author.I will remember to bookmark your blog and definitely will come back in the future. I want to encourage that you continue your great writing, have a nice afternoon!

  6. I used to be recommended this web site by way of my cousin. I’m not certain whether this submit is written via him as nobody else understand such special approximately my problem. You’re incredible! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *