Let us learn about C programs and their important features, applications, data types and examples in this article. C programming language is one of the oldest programming languages used for developing operating systems, databases, etc. Most students begin their college or school careers with C programming.
The C programming language serves as the basis for all other programming languages. Various institutes and colleges also include C programming in their syllabus, as it forms a strong basis for students to follow.
About C programming
C programming is a powerful and oldest programming language developed in the 1970s by Deniis Ritchie at Bell Labs. It was a very famous language in the 1990s and was everybody’s choice because no one had much idea about what programmers could do.
Still, C programming is the first choice for students who are new to programming. Most colleges and institutes and even examinations, are taken on the basis of the C programming language. We need to define our data type when defining a variable in C programming. This helps the C compiler understand the type of data and the operations it can perform.
All other languages that we have in 2024 are based on the C language. It forms the foundation of programming and C++ is a widely used programming language that is an extension of the C language.
Features of C Programming Language
C program was developed by Dennis Ritchie as a system level programming language to write operating systems. Some of the major features of the C programming language are mentioned below.
- C programming language is a procedural language as it contains code blocks to solve a given problem. These programming languages are easy to debug because of their definite structure.
- It is fast and efficient and allows direct access to system hardware and memory, which helps it easily perform low level programming tasks.
- The C level programming languages are statically typed general purpose languages. We need to declare the types of variables during compile time.
- The C programming language provides functions and libraries to help solve complex tasks using functions and perform specific tasks.
- It is used for various tasks, such as application development, system programming, game development, etc.
- C program consists of standard libraries, which consists of pre-built methods to perform various functions such as memory management, mathematical operations, etc.
- It consists of various built in operators that can be used to simplify complex programs while coding.
- It supports cross platform operating systems such as Windows, Linux, ioS, android, etc.
- It is used with database language to manage and modify data stored. Some of the applications are Oracle, PostgreSQL, My SQL, etc.
- C language also provides a vast community support which provides various online resources, materials, and libraries for free.
- It is a middle level language that supports low level as well as high level programming tasks.
- The programs written in the C language are portable through systems and can run and compile on any system with either no changes or very small changes.
- C programming language can easily be extended and integrated with extra features and operations.
What are Data Types in C?
Data Types are built in information that is used to differentiate between the types of values stored inside the variable. Some of the built in data types in C language are Integer, float, character, double, boolean, etc. All the possible operations and processes that can be performed on a variable are determined by its data type.
The four main basic data types in C are int, char, float, and double. Also, signed modifier means you can have negative as well as positive values in the given variable and unsigned modifier means you can only have positive values inside a variable. Data types are containers that decide what can be contained inside.
For example: In a bottle, we can only put juice, water and other fluid substances. We cannot put watches, boxes, books in the bottle as it will not fit. Similarly, an integer (int) data type can store only integer values.
Example of Data Types in C
Consider a class with students having name, roll no, phone no, address, fathers, mothers names, subjects names, ages, etc. Let us classify them as primitive data types in C to better understand the meaning of data types.
Integer (int): roll number, age
String: name, subjects, mother name, father name, phone number
Primitive Data Types in C Programming Language
There are four major classifications of data types mentioned below.
1. Integer Data Type (int)
This data type stores the integer value (whole numbers) inside a variable. It consists of no decimals and can be negative or positive. For example, check the table below.
Data Types in C |
#include <stdio.h>
void main() { int x = 10; printf(“The integer value in the variable is %d\n”,x); } |
2. Character Data Type in C
This data type stores the character value represented by ASCII character sets. It is represented by single quotes.
Data Types in C |
#include <stdio.h>
void main() { char ch = ‘a’ printf(“The integer value in the variable is %c\n”,ch); } |
3. Floating Point Data Type
It is represented by ‘float’. It consists of all the real number values inside a variable. It supports decimal and fraction numbers. Check for the example below.
Data Types in C |
#include <stdio.h>
void main() { float y = 3.14; printf(“The floating point value in the variable is %f\n”,y); } |
4. Double Data Type
This is used to store values that do not fall under the range given under integer or floating point data type. Check out the example below.
Data Types in C |
#include <stdio.h>
void main() { double d = 21.987654 e-7; printf(“The double point value in the variable is %lf\n”,d); } |
About C Program: Void Data Type
The void data type in C is used to represent a variable having no specific data type. It is used at various places in programming to indicate that a given variable has no return value. Functions with ‘void’ data types return no value after execution.
Data Types in C |
#include <stdio.h>
void main() //Main function returns no value after execution of code. { //Code } |
About C Program: Derived Data Type
There are many derived data types in C programs, such as Union, Structure, enum, array, etc.
1. Structure
Structures are used to declare user defined data types under a single variable. It is declared using the ‘struct’ keyword. Check out the example of a Person structure in the table below that has name, age, and salary as its members.
Data Types in C |
#include <stdio.h>
struct Person { char name[50]; int age; float salary; }; struct Person employee; |
2. Union
A union data type in the C language is used to hold different types of data in a single place by joining them together.
Data Types in C |
#include <stdio.h>
union name { datatype name1; datatype name2; } |
3. Arrays
Arrays are used to store lists of the same type of variables in a single variable. Elements inside an array are stored at contiguous memory locations. It can easily be declared using a square bracket. Check out an example below.
Data Types in C |
#include <stdio.h>
int x [4]; //Declare an array with name ‘x’ that consists of 4 elements. |
4. Enums
Enums or enumeration in C, are a user defined data type used to store named integers inside. The use of integer names helps to make code easier to understand. Check an example given below.
About C Program: enums |
#include <stdio.h>
// Define an enum named Color with three possible values enum Color { RED, GREEN, BLUE }; |
Learn Programming with PW Skills
Join our Online programming courses to learn programming from the best experienced faculties and affordable courses. Throughout the course we will guide you through the concepts and also help you gain exposure through 100% placement assistance. You can also practise with many exercises, quizzes and online study materials provided with the course. Practice coding with PW Labs completely for free. Know more only at @pwskills.com
About C Programming Language FAQs
Why is C called a procedure programming language?
C is a procedural programming language, as it consists of blocks of codes arranged in a sequential manner. It makes debugging easy.
Is C an object oriented programming language?
No, C is not an object oriented programming language. It does not support classes and objects.
What are the various data types in the C language?
C programming supports various data types such as integer, float, double, array, char, union, structure, enums, etc.
What do you mean by data type?
Data type in C is used to tell what permitted values a variable can store, which also determines the operations it can perform.