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.
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;
Conceptual
figure
Primary Data Types
Description
Primary Data types are also called as Fundamental Data Types. Types of primary data can be given as follows.
Types
Integer Data Type
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) 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 1 byte.
2) The range lies between -128 and 127.
Floating point Data Type
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) "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
Description
Void data type represents no value.
void type does not have any values.
void type does not return values (for functions).
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
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
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
Key Points
C Data Types defines type of data.
Integer(%i) has unsigned,signed,short and long types.