GET EDUCATE

Contents
Basics of C Programming

⯈Basic C Programs

Data types in C

Datatypes says the type of data that we want to store. It also says the amount of memory the data takes. Datatypes also specifies the operation that we can carry out on the particular data. The data types are designed to store the values, the values are same as that of constants that we have discussed. We need datatypes to store integers, real numbers, characters and strings. There are different types of data types:

  1. Primitive data type.
  2. User defined data type.
  3. Derived data type.

You may watch the video posted at the end of the page.

Data Type Description
Primitive Data Type
These are most basic data types. These are used to store integers, characters and real numbers.
int, float, double, char and void are primitive data types.
User Defined data type
These data types are defined by the user by combining the primitive data types together.
struct, union and enum are user defined datatypes.
Derived data type
These datatypes are extension of the primitive or user defined data types.
Arrays are derived datatype.

Primitive data type

These are the most basic data types. The primitive data types are used to store integers, real numbers and characters. The primitive data types are int, float, double, char and void.

We shall discuss these one by one in detail.

int

  • int is a keyword.
  • We can store integer values in this data type.
  • Range of int datatype is from -2,147,483,648 to 2,147,483,647. 
  • The sizeof  int datatype is 4 bytes (32 bits)
  • Format specifier: %d or %i

Note:

  • The sizeof int depends on the compiler. Some compiler takes 2 bytes and some compiler takes 4 bytes of data.
  • The integer data types can also be used as:
    • unsigned int: We can only store positive numbers. The range of unsigned int is 0 to 4294967295. 
    • short int: This is used to store the lesser values. It takes 2 bytes of data. The range is from -32768 to 32767.
    • long long int: This is used to store the larger values than the integer. It takes 8 bytes of data. The range is from -9223372036854775808 to 9223372036854775807.

float

  • float is a keyword.
  • It is used to store real numbers.
  • It has precision of 6 digits.
  • The range of float datatype is from 1.2E-38 to 3.4E+38.
  • It takes 4 bytes of data.
  • The real numbers are stored in IEEE – 754 format.
  • Format Specifier: %f

double

  • double is a keyword.
  • It is used to store real numbers.
  • It has precision of 16 digits.
  • It takes 8 bytes of memory.
  • The real numbers are stored in IEEE – 754 format.
  • Range is from 1.7E-308 to 1.7E+308
  • Format Specifier: %lf

char

  • char is a keyword.
  • It is used to store single character.
  • It takes 1 byte of data type.
  • The range is from 0 to 255.
  • Format specifier: %c

void

  • void is a keyword.
  • This doesn’t represent any value.
  • It is used to represent that no-value is returned from the function.
  • It is also used to represent the void pointers.
Note: The long, short and signed can be used with any primitive data type to change the range of data that we want to store.

User defined data type

These data types are defined by the user. struct, union and enum are the user defined data types. 

We shall discuss these in the coming chapters.

Derived data type

These datatypes are derived or extension of user-defined or primitive data types. Arrays are derived data types. We shall discuss the arrays in coming chapters.

In the next section we shall discuss variables.

Scroll to Top