Data Types in C Language
88A programming language is proposed to help programmer to process certain kinds of data and to provide useful output. The task of data processing is accomplished by executing series of commands called program. A program usually contains different types of data types (integer, float, character etc.) and need to store the values being used in the program. C language is rich of data types. A C programmer has to employ proper data type as per his requirement.
C has different data types for different types of data and can be broadly classified as :
- Primary data types
- Secondary data types
Primary data types consist following data types.
Data Types in C
Integer types:
Integers are whole numbers with a range of values, range of values are machine dependent. Generally an integer occupies 2 bytes memory space and its value range limited to -32768 to +32768 (that is, -215 to +215-1). A signed integer use one bit for storing sign and rest 15 bits for number.
To control the range of numbers and storage space, C has three classes of integer storage namely short int, int and long int. All three data types have signed and unsigned forms. A short int requires half the amount of storage than normal integer. Unlike signed integer, unsigned integers are always positive and use all the bits for the magnitude of the number. Therefore the range of an unsigned integer will be from 0 to 65535. The long integers are used to declare a longer range of values and it occupies 4 bytes of storage space.
Syntax: int <variable name>; like
int num1;
short int num2;
long int num3;
Example: 5, 6, 100, 2500.
Integer Data Type Memory Allocation
Floating Point Types:
The float data type is used to store fractional numbers (real numbers) with 6 digits of precision. Floating point numbers are denoted by the keyword float. When the accuracy of the floating point number is insufficient, we can use the double to define the number. The double is same as float but with longer precision and takes double space (8 bytes) than float. To extend the precision further we can use long double which occupies 10 bytes of memory space.
Syntax: float <variable name>; like
float num1;
double num2;
long double num3;
Example: 9.125, 3.1254.
Floating Point Data Type Memory Allocation
Character Type:
Character type variable can hold a single character. As there are singed and unsigned int (either short or long), in the same way there are signed and unsigned chars; both occupy 1 byte each, but having different ranges. Unsigned characters have values between 0 and 255, signed characters have values from –128 to 127.
Syntax:
char <variable name>; like
char ch = ‘a’;
Example: a, b, g, S, j.
Void Type:
The void type has no values therefore we cannot declare it as variable as we did in case of integer and float.
The void data type is usually used with function to specify its type. Like in our first C program we declared “main()” as void type because it does not return any value. The concept of returning values will be discussed in detail in the C function hub.
Secondary Data Types
Secondary data types will be discussed in details when we will use them in our program later.
User defined type declaration
C language supports a feature where user can define an identifier that characterizes an existing data type. This user defined data type identifier can later be used to declare variables. In short its purpose is to redefine the name of an existing data type.
Syntax:
typedef <type> <identifier>; like
typedef int number;
Now we can use number in lieu of int to declare integer variable. For example: “int x1” or “number x1” both statements declaring an integer variable. We have just changed the default keyword “int” to declare integer variable to “number”.
|
C How to Program (5th Edition)
Price: $58.38
List Price: $123.00 |
|
Problem Solving and Program Design in C (6th Edition)
Price: $59.00
List Price: $105.00 |
|
C How to Program Introducing C++ and Java
Price: $38.50
List Price: $115.00 |
|
Object-Oriented Program Development Using C++: A Class-Centered Approach
Price: $70.00
List Price: $122.95 |
Become Master of C Language using These Books
|
Programming in C (3rd Edition)
Price: $29.13
List Price: $49.99 |
|
Gtk+ Programming in C
Price: $25.84
List Price: $44.99 |
|
An Introduction to Object-Oriented Programming in C++: with Applications in Computer Graphics
Price: $60.13
List Price: $115.00 |
|
Parallel Programming in C with MPI and OpenMP
Price: $58.67
List Price: $68.80 |
Data Types in C, Size & Range of Data Types.
Related C Programming Tutorials
- A Brief History of the C Language
Before we start any complex program in C, we must understand what really C is, how it came into existence and how it differs from other languages of that time. In this tutorial I will try to talk about these... - What is Function in C Language?
A function in C language is a block of code that performs a specific task. It has a name and it is reusable i.e. it can be executed from as many different parts in a C Program as required. It also ... - Types of Function in C Programming Languages:
In my previous c programming tutorial I tried to explain what the function, its advantages is and how to declare a C function. And I told you that there are five types of functions and they are: ... - Array in C programming Programmer's view
An array in C language is a collection of similar data-type, means an array can hold value of a particular data type for which it has been declared. Arrays can be created from any of the C data-types int,... - How to work with Two Dimensional Arrays in C
We know how to work with an array (1D array) having one dimension. In C language it is possible to have more than one dimension in an array. In this tutorial we are going to learn how we can use two... - How to work with Multidimensional Array in C Programming
C allows array of two or more dimensions and maximum numbers of dimension a C program can have is depend on the compiler we are using. Generally, an array having one dimension is called 1D array, array... - Turn Your PC Keyboard to Musical Keyboard using C Program
To accomplish this task you dont need to buy any expensive software or hardware, only a little knowledge of C program will do and you can build your own musical keyboard software. Before we begin you... - File Copy Program in C Language
Today we are going to learn a simple file copy program in C language. As I said this is a simple file copy program so you should not expect its output like DOS copy command has. Ok lets start. The main...
Useful Links
- How to share an internet connection on LAN?
If you have a fully functional LAN then net sharing is few click away, yes few clicks. I assumed that you have already a broadband connection and account configured on your PC. Just go to “My Network... - A Brief History of the C Language
Before we start any complex program in C, we must understand what really C is, how it came into existence and how it differs from other languages of that time. In this tutorial I will try to talk about these... - Your First C Program
You might be thinking that you have learnt lot about C language background and now eagerly want to try your first program in C. To do so first of all you need a C compiler, I have been using Turbo C++... - What is LAN (Local Area Network) ?
LAN is acronyms of Local Area Network. LAN is required everywhere, whether it is office home or somewhere else. LAN is a small computer network (small version of internet) covering a small area like home,... - How to work from home on internet
How to make money online? This is the common and highest searched term on internet. You will also get numerous answers to this query. But, before following any answer, please make sure which type of money...
PrintShare it! — Rate it: up down flag this hub
Comments
An enum is an integer type.
what is boolean in data type
blooean is also a data type which can hold value like true or false (0 or 1). But boolean is not supported in C, boolean is supported in languages like C#, PHP, etc.
well this site is really useful n had helped me a lot in solving my confusions n doubts
love u











sreeemay says:
8 months ago
ur tought is so good try to write some other programms and refference books