Saturday, June 30, 2018

C programming data types



C data types format specifiers is important topic. These data types in C is easy topic as well. You will use these in most programs. You will use data types in C to refer extensive system. This system will declare either functions or C variables. In addition, variables and functions can be of different types. You will learn more about data types in C with examples here.
You must remember that variable type determines space. This space is about storage. Moreover, it interprets bit pattern stored. However, these C data types have different classification. Keep reading to know more about them.


Name of data typeDescription
Basic TypesThese are arithmetic types. Classification is as follows: integer types and the floating-point types
Derived typesPointer, Array, Structure, Function and Union types
Enumerated typesThese are also arithmetic types. They define variables. These can assign certain discrete integer values in program
The type voidType specifier void will state that there is no value
Array and structure types together are aggregate types. You must remember that function type indicates return value of function.

List of standard integer types, storage sizes and value range

TypeValue rangeStorage size
unsigned char0 to 2551 byte
char-128 to 127 or 0 to 2551 byte
signed char-128 to 1271 byte
int-32,768 to 32,767 or -2,147,483,648 to 2,147,483,6472 or 4 bytes
unsigned int0 to 65,535 or 0 to 4,294,967,2952 or 4 bytes
long-2,147,483,648 to 2,147,483,6474 bytes
unsigned long0 to 4,294,967,2954 bytes
short-32,768 to 32,7672 bytes
unsigned short0 to 65,5352 bytes

sizeof operator in C

You may use sizeof operator in C. This will get exact size of variable or type. In addition, sizeof(type) will yield storage size of object. Or even the type in bytes.
Example program

Void type in C programming language

Name of the typeDescription
Function returns as voidYou must remember that many functions in C do not return any value or return void. Additionally, function with no return value has void as return type. Example void exit (int status);
Pointers to voidA pointer of type void * will represent address of object. However, it will not be type. Example is memory allocation function void *malloc( size_t size );
Because here, it will return pointer to void. Moreover, you can cast it to other data type
Function arguments as voidApart from above two, there are other functions in C. These functions do not accept parameters. So, remember that a function with no parameter can never accept void. Example is int rand(void);


Floating-point type in C programming language

Name of the TypeValue rangeStorage sizePrecision
float1.2E-38 to 3.4E+384 byteIt is 6 decimal places
long double3.4E-4932 to 1.1E+493210 byteHere, there are 19 decimal places
double2.3E-308 to 1.7E+3088 byteIt is 15 decimal places
Header file float.h will define macros. Macros in C language allow you to use values and real numbers in programs. Also know about Operators in C.
Example program

















No comments:

Post a Comment