Data types in c programming language

Data types in c programming language


Data types in c programming language
Data types in c programming language

DATA TYPES

The data type defines the type Of data stored in a memory-location and allocates memory for the data.
The number of bytes allocated is based on the architecture of the machine.


C supports three classes Of data types:

1. Primitive data type
Example: int, float, char, double, void

2. Derived data types
Example: signed, unsigned

3. User-defined data types
Example: structure

data-type-c
Data Type C
1. The primitive data type ( also known as primary or basic data type )

Example: int, float, char, double, void

1.  int (integer)

  • An int is a keyword which is used to define integers.
  • Using int keyword, the programmer can inform the compiler that the data associated with this keyword should be treated as an integer.
  • An integer is used to store the whole number with the range Of values supported by a particular machine.
  • Generally, integer occupies one word Of storage of machine which generally Varies.(i.e. 16 or 32).
  • C supports three different sizes Of integer as shown in figure 2.5
  1. short int (2 bytes)
  2. .int (4 bytes)
  3. long int (8 bytes)
int-c
int-in-c

2.   float (floating point)

  • A float is a keyword which is used to define floating-point numbers.
  • It allocates 4 bytes of memory Out of which 6 digit precision is provided.

3.   double (floating-point double precision)

  •   A double is a keyword used to define long floating-point numbers.
  •   It allocates 8 bytes of memory Out of which 14 digit precision is provided.
  •   The long double allocates 16 bytes in which it has 80 bits precision.
  •   The floating-point supports both types Of values storage i.e. fractional values and scientific value.
float
float

4. char (Character)

  • A char is a keyword which is used to define a single character.
  • One byte Of memory is allocated by char.
  • Similar to integer char also comes with signed and unsigned versions.

5. Void

  •  void is an empty data type. Since no value is associated with this data type, but it allocates one byte in the memory.
  •   This is normally used in functions to indicate that the function does not return any value.
  •   It can also play a role Of a generic type in C, i.e. which can represent any of the Other standard types.
A simple program example which illustrates the number Of bytes allocated for basic data type in 32 bit machine.
# include<stdio.h>  
void main ( )
{
          print f (" * * *  *The Number of bytes allocated for primary
data-type-c
Data Type in c
  • Derived Data type and User define data types are data type which is derived from primitive data type or basic data type.
Video tutorial:

No comments:

For Query and doubts!

Powered by Blogger.