C Programming - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

C Data Types

C Data Types

shape Description

Every programming language consists of some kind of data. Datatype shows the specific data entered into a program. C Data Types are the keywords used to declare the type of the variable used in the program such as integer, real, character and string.

shape Syntax

Below is the syntax for C Data Types. The type of data has to be provided in the place of datatype.
datatype variable_name;

shape Conceptual figure

Primary Data Types

shape Description

Primary Data types are also called as Fundamental Data Types. Types of primary data can be given as follows.

shape Types

Integer Data Type

shape Description

Integer data type is used to denote an integer type i.e they store only the whole numbers without decimal places.
  • The keyword used is "int".
  • Format Specifier for integer data type is "%d". (Format specifier is used to display/print integer values using any output functions such as 'printf', and 'print')
1) Integer data types are whole numbers which does not allow the precision i.e decimal places. 2) Occupies 2 bytes of memory. 3) The range lies between -32768 and +32767.
1) Takes only the positive values. 2) The memory is 2 bytes. 3) The range is double the signed 'int' i.e. 0 to 65535.
1) Needs less space in memory. 2) Memory Size is 1 byte. 3) short int a; and int a; both are same.
Same as unsigned int which occupies less space.
1) If the memory required is more than int and short int then long int is used. 2) Takes 4 bytes of memory space. 3) The range lies between -2147483648 and + 2147483647.
1) The size is same as signed long int. 2) The range lies between 0 and 42949672954.

Character Data Type

shape Description

Character data type is used to denote character value. The keyword used is "char". Format specifier for character data type is "%c".
1) "char" occupies 1 byte of memory. 2) The range lies between 0 and 255.
1) The size is 1 byte. 2) The range lies between -128 and 127.

Floating point Data Type

shape Description

Floating point data type is used to denote the decimal places for integer values. The keyword used is "float". The format specifier for floating point data type is "%f ".
1) "float" occupies 4 bytes of memory. 2) The range lies between -3.4E+38 and +3.4E+38.
1) "double" occupies 8 bytes of memory. 2) The range lies between -1.7E+308 and +1.7E+308. 3) The format specifier for %lf.
1) "long double" occupies range of 10 bytes of memory. 2) The range is same as double. 3) The format specifier is %Lf.

Void data type

shape Description

Void data type represents no value.
  • void type does not have any values.
  • void type does not return values (for functions).

shape Examples

[c] #include<stdio.h> #include<conio.h> void main() { char c; int x, y; float f1, f2; double d1, d2; unsigned p; int a = 4321; long int l = 5432167; c = 'A'; x = 867; f1 = 4.3214; d1 = 8.5467342; f2 = 20.000; d2 = 3.0; printf("c = %c \n", c); printf("x = %d and y = %d \n", x, y); printf("l = %ld \n", l); printf("d1 = %07lf \n", d1); printf("p = %u \n", p); } [/c]

User-defined Data Types

shape Description

User-defined data type is used when user wants to define an identifier and that identifier can be later used for variables.

typedef

"typedef" is one such user defined data type which is used to declare variables.Below is the syntax for typedef.
typedef int numbers { numbers n1; numbers n2; }

enum

"enum identifier" is an other datatype. The variables are stored in braces {}.Below is the syntax for enum.
enum identifier {value1,value2,value3,.....};

Derived Data Type

shape Description

As the name itself denotes, derived data types are derived from primary data types. They includes Arrays, Pointers, Structures, Unions and Functions. These concepts will be discussed in further chapters.

Summary

shape Key Points

  • C Data Types defines type of data.
  • Integer(%i) has unsigned,signed,short and long types.
  • float(%f) has double and long double types.
  • char(%c) has signed and unsigned types.
  • void doesn't return any value.
  • typedef and enum are user-defined data types.