
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What are different types of data in C language?
Datatype is the declaration of memory location or variable. Data can be of different types and some of the examples of data types in C language are as follows −
Integers, rational numbers, whole numbers, real numbers, complex numbers, vectors, characters etc.
Coming to the machine hardware, the data is everything encoded as a string of binary digits 0 and 1 of finite length. In the machines, the integer data is processed in the arithmetic logic unit (ALU) and fractional data is processed in the floating-point unit (FPU). This gets reflected in the built-in or primitive data types of a high-level language.
Built-in data types
In the C language, there are different built-in data types and some of them are shown below −
Int, float, char, unsigned int, unsigned char, long int, double etc.
Use of data
In the C language the data can be stored in different ways by using different types. Some of the examples are mentioned below −
- char string, grade=’A’;
- int count, index=10;
- float average=6.9;
In the above example chat, int, float are built-in data type, whereas string, grade are variables of type char.
Grade=’A’ initializes the variable grade to character code of ‘A’.
Count and index are variables of type int.
And index=10 initializes the variables to binary representation of 10.
Example
Given below is the C program to find out the size of variable and built-in data type −
#include<stdio.h> int main(){ int x = 10; char c; printf("Size of variable x = %ld bytes
",sizeof(x)); printf("Size of variable c = %ld byte
",sizeof(c)); printf("Size of short is %ld bytes
",sizeof(short)); printf("Size of int is %ld bytes
",sizeof(int)); printf("Size of long is %ld bytes
",sizeof(long)); printf("Size of float is %ld bytes
",sizeof(float)); printf("Size of double is %ld bytes
",sizeof(double)); printf("Size of long double is %ld bytes
",sizeof(long double)); printf("Size of char is %ld bytes
",sizeof(char)); printf("Size of void is %ld bytes
",sizeof(void)); return 0; }
Output
When the above program is executed, it produces the following result −
Size of variable x = 4 bytes Size of variable c = 1 byte Size of short is 2 bytes Size of int is 4 bytes Size of long is 4 bytes Size of float is 4 bytes Size of double is 8 bytes Size of long double is 16 bytes Size of char is 1 bytes Size of void is 1 bytes
- Related Articles
- What are different types of constants in C language?
- What are the different types of pointers in C language?
- What are the different types of keywords in C language?
- What are primary data types in C language?
- What are the different data types of arrays in C#?
- What are different Perl Data Types?
- What are types of expressions evaluated in C Language?
- What are different types of constants in C++?
- What are the different data types in Apache Pig?
- What are the different data types used in SQL queries?
- What are the different searching techniques in C language?
- What are different format specifiers used in C language?
- What are the different types of Python data analysis libraries used?
- What are enumerated data types in C++?
- What are pointer data types in C#?
