About Us

Popular Updates Of Last Week

Search This Website

Tuesday 1 August 2017

What Is Data Types In C & How many types are there?

What Is Data Types In C & How many types are there?




v \Data Types are used to:
Ø  Identify the type of a variable when it declared.
Ø  Identify the type of the return value of a function.
Ø  Identify the type of a parameter expected by a function.

v Types Of Data Types :

click here to check C Programs


FBASIC DATA TYPES IN C LANGUAGE 


Ø INTEGER DATA TYPE:

·      Integer data type allows a variable to store numeric values.
·      “int” keyword is used to refer integer data type.
·      The storage size of int data type is 2 or 4 or 8 byte.
·      It varies depend upon the processor in the CPU that we use.  If we are using 16 bit processor, 2 byte (16 bit) of memory will be allocated for int data type.
·      Likewise, 4 byte (32 bit) of memory for 32 bit processor and 8 byte (64 bit) of memory for 64 bit processor is allocated for int datatype.
·      If you want to use the integer value that crosses the limit, you can go for “long int” and “long long int” for which the limits are very high.

Ø CHARACTER DATA TYPE:

 ·       Character data type allows a variable to store only one character.
·     Storage size of character data type is 1. We can store only one character using character data type.
·    “char” keyword is used to refer character data type.
·        For example, ‘A’ can be stored using char datatype. You can’t store more than one character using char data type.

Ø FLOAT:

·         Float data type allows a variable to store decimal values.
·         Storage size of float data type is 4. This also varies depend upon the processor in the CPU as “int” data type.
·         We can use up-to 6 digits after decimal using float data type.
·         For example, 10.456789 can be stored in a variable using float data type.

Ø DOUBLE:

·      Double data type is also same as float data type which allows up-to 10 digits after decimal.
·      The range for double datatype is from 1E–37 to 1E+37.

FDERIVED DATA TYPE IN C LANGUAGE:

Ø  Array:

·     A normal C variable can hold only one data of one data type at a time.
·     An array can hold group of data of same data type.
·     Its made by the user/programmer
·     Syntax:
    Data_type variable name[size];
           ·     Example:  int a[5]; 
           ·     From this example a array is made of integer data type of size 5.
           ·     We wrote this instead of writing “int a1,a2,a3,a4,a5”.

Ø Structure:

  • In C Structure is a collection of different data types which are grouped together and each element in a C structure is called member.
  • If you want to access structure members in C, structure variable should be declared.
  • Many structure variables can be declared for same structure and memory will be allocated for each separately.
·        Syntax:
  Struct <Structure_name>
  {
    data_type  member1;
    data_type  member2;
    ……
  }

·        Example:
struct student
{
int a;
char b[10];
}

Ø enum:

·        Enumeration data type consists of named integer constants as a list.
·        It start with 0 (zero) by default and value is incremented by 1 for the sequential identifiers in the list.
·        Enum Syntax in C:
enum identifier [optional{ enumerator-list }];
·        Enum example in C: 
enum month { Jan, Feb, Mar }; or
/* Jan, Feb and Mar variables will be assigned to 0, 1 and 2 respectively by default */
enum month { Jan = 1, Feb, Mar };
/* Feb and Mar variables will be assigned to 2 and 3 respectively by default */
enum month { Jan = 20, Feb, Mar };
/* Jan is assigned to 20. Feb and Mar variables will be assigned to 21 and 22 respectively by default */



          

No comments:

Post a Comment