C Programming Data Types

C programming refers to a comprehensive system used to declare data types, variables, or different types of functions.The type of variable determines how much space it takes up in storage and how the stored bit model is interpreted.

Data types in C can be classified as follows:

Sr.No.Types and Description
1Base Types
They are arithmetic types and are also classified as: (a) integer types and (b) floating-point types.
2Numbered Types
They are also arithmetic types and are used throughout the program to identify variables that can assign only certain discrete integer values.
3Void Types
The type token void indicates that there are no values available.
4Derived Types
They are classified as (a) Pointer(Pointer types), (b) Array(Array types), (c) Struct(Build types), (d) (Union)Join types, and (e) Function(Function types).

Array types and build types are collectively called bulk types.The type of a function specifies the type of return value of the function.We will see the basic types in the following section, other species will also be discussed when they need to be used in the following sections.

Integer Types

The following table provides details of standard integer types, along with storage sizes and value ranges:

TypeStorage SizeValue Range
Char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0with 255
signed char1 byte-128with 127
Int2or 4 bytes-32,768with 32,767or -2,147,483,648with 2,147,483,647
unsigned int2or 4 bytes0 to 65,535or 0with 4,294,967,295
Short2 bytes-32,768with 32,767
unsigned short2 bytes0with 65,535
Long8 bytes or
(4 bytes for 32-bit operating system)
-92233720368547758089223372036854775807
unsigned long8 bytes018446744073709551615

You can use the sizeof operator to obtain the full size of a type or variable on a given system. sizeof(type) expressions give the storage size of the object or its type in bytes.The following is a preprocessor type used to obtain the size of various types on a machine that uses the different constants defined in the limits.h header file.

#include <stdio.h></stdio.h>  #include <stdlib.h></stdlib.h>  #include <limits.h></limits.h>  #include <float.h></float.h>  int main(int argc, char** argv) {

printf("CHAR_BIT : %dn", CHAR_BIT);
    printf("CHAR_MAX : %dn", CHAR_MAX);
    printf("CHAR_MIN : %dn", CHAR_MIN);
    printf("INT_MAX : %dn", INT_MAX);
    printf("INT_MIN : %dn", INT_MIN);
    printf("LONG_MAX : %ldn", (long) LONG_MAX);
    printf("LONG_MIN : %ldn", (long) LONG_MIN);
    printf("SCHAR_MAX : %dn", SCHAR_MAX);
    printf("SCHAR_MIN : %dn", SCHAR_MIN);
    printf("SHRT_MAX : %dn", SHRT_MAX);
    printf("SHRT_MIN : %dn", SHRT_MIN);
    printf("UCHAR_MAX : %dn", UCHAR_MAX);
    printf("UINT_MAX : %un", (unsigned int) UINT_MAX);
    printf("ULONG_MAX : %lun", (unsigned long) ULONG_MAX);
    printf("USHRT_MAX : %dn", (unsigned short) USHRT_MAX);

return 0;
}





When you compile and run the above program, it produces the following result in MacOS:

CHAR_BIT :   8
CHAR_MAX :   127
CHAR_MIN : -128
INT_MAX :   2147483647
INT_MIN : -2147483648
LONG_MAX :   9223372036854775807
LONG_MIN : -9223372036854775808
SCHAR_MAX :   127
SCHAR_MIN : -128
SHRT_MAX :   32767
SHRT_MIN : -32768
UCHAR_MAX :   255
UINT_MAX :   4294967295
ULONG_MAX :   18446744073709551615
USHRT_MAX :   65535

Floating-Point Types

The following table provides details and certainty of standard floating-point types with storage sizes and value ranges:

TypeStorage SizeValue RangePrecision
Float4 bytes1.2E-38 vs 3.4E+386 decimal places
Double8 bytes2.3E-308 with 1.7E+30815 decimal places
long double10 bytes3.4E-4932 with 1.1E+493219 decimal places

The Float.h header file defines data that allows you to use these values and other details about binary representation of actual numbers in your programs.The following example prints the storage and range values received by a floating-point type:

#include <stdio.h></stdio.h>  #include <stdlib.h></stdlib.h>  #include <limits.h></limits.h>  #include <float.h></float.h>  int main(int argc, char** argv) {

printf("Storage size for float : %d n", sizeof(float));
    printf("FLT_MAX : %gn", (float) FLT_MAX);
    printf("FLT_MIN : %gn", (float) FLT_MIN);
    printf("-FLT_MAX : %gn", (float) -FLT_MAX);
    printf("-FLT_MIN : %gn", (float) -FLT_MIN);
    printf("DBL_MAX : %gn", (double) DBL_MAX);
    printf("DBL_MIN : %gn", (double) DBL_MIN);
    printf("-DBL_MAX : %gn", (double) -DBL_MAX);
    printf("Precision value: %dn", FLT_DIG );

return 0;
}





When you compile and run the above program, it produces the following result in MacOS:

Storage size for float : 4 
FLT_MAX :   3.40282e+38
FLT_MIN :   1.17549e-38
-FLT_MAX : -3.40282e+38
-FLT_MIN : -1.17549e-38
DBL_MAX :   1.79769e+308
DBL_MIN :   2.22507e-308
-DBL_MAX : -1.79769e+308
Precision value: 6

Void Type

The void type indicates that there is no value available.It is used in three types of situations:

Sr.No.Types and Description
1Return function invalid
There are several functions in C that do not return any values, or you can say that they return void.A function without a return value has the return type void.
For example, void exit (int status);
2function arguments as void
There are several functions in C that do not accept any parameters.A function without parameters can accept a space.
For example, int rand(void);
3To override pointers,
a pointer of type void * represents the address of an object, but it does not represent its type. 
For example, a memory allocation function void *malloc(size_t you); returns an invalid pointer that can be converted to any data type.

Format Tokens

Format tokens are used in C for input and output purposes.Using this concept, the compiler can understand what type of data is in a variable when importing input using the scanf() function and printing using the printf() function.

Format TokenType
%cCharacter
%dSigned integer
%e or %EScientific notation of floats
%fFloat values
%g or %GSimilar as %e or %E
%hiSigned integer (short)
%huUnsigned Integer (short)
%iUnsigned integer
%l or %ldor %liLong
%lfDouble
%LfLong double
%luUnsigned int or unsigned long
%llior %lldLong long
%lluUnsigned long long
%oOctal representation
%pPointer
% sString
%uUnsigned int
%xor %XHexadecimal representation
%nPrints nothing
%%Prints % character