C Tutorial
C is a widely used programming language. It is considered as the base for other programming languages. This C Tutorial helps programmers with C basics like environment setup, variables, operators, conditional statements, control statements, looping statements, string operations, basic IO operations, file operations, etc. with well detailed C Programs as examples.
C Programming for Beginners
Along with the above said topics, you will get the intuition about the programming approach in solving problems with the help of C language.
C Programming Language
About
C is a general purpose, procedure oriented programming language developed in 1972 by Dennies M.Ritchie at Bell laboratories of AT&T(American Telephone & Telegraph) located at U.S.A.
C language is developed for creating system applications that interacts directly to the hardware devices such as drivers, kernels, etc. Initially, C language was developed to program the Unix Operating system. C language has overcome the problems of previous languages such as B, BCPL.
Introduction to C Programming
C programming is one of the most powerful languages. It is used as a base for other languages. Most of the languages such as C++, Java, etc., follow C syntax.
C programming language can be defined in different ways. They are :
- Sequential Programming (Sequential flow of program execution)
- Imperative Programming Language (Changes the state of program using statements)
- Procedural Language (follows series of steps or procedures )
- Structured Programming Language(break a program into parts or modules)
- System Programming Language (used to do low level programming )
- Mid-level Programming Language (supports features of both low and high level languages)
Sequential Programming
In sequential programming, the execution of statements is done sequentially from top to bottom, one by one. In C programming, the execution generally starts at main method and executes the statements inside it one by one from top to bottom. Any control statements, conditional statements, looping statements or functional calls makes the execution flow jump to a particular location in the program.
Imperative Language
In an imperative language, the state of the program is altered with the help of statements executed one by one. In C program, the state of the program is stored in the variables and the statements in modifying the state of the program which eventually helps in solving a problem.
Procedural Language
C is also known as a procedural language because it specifies a series of steps or procedures for a program to solve a problem. A programmer can group a set of statements in a function or routine (also called procedure). The procedure can be called any number of times from anywhere in the program. This helps the programmer to organize the code in modules which could be reusable and improve the understandability of the program.
Structured Programming
C is called structured programming language because to solve a large problem, c programming language divides a problem into smaller modules called functions or procedures.
For example, to calculate student percentage, some of the procedures are input student marks, add marks, calculate percentage, display result.
System Programming
System programming language is used to create computer software. C language can be used to do low level programming like driver, firmware, kernel, etc. System software interacts directly with hardware devices such as OS, drivers etc. Widely used Linux Kernel is written in C and Assembly programming languages. Most of extreme gaming applications use C programming for low latency.
Mid-level Programming
A low level programming language (like assembly) is more machine friendly. Though the instruction set is limited, it takes lot of effort to expertise in a low level programming language and takes more number of lines to code to solve a problem.
A high level programming language (like COBOL,PASCAL,BASIC, etc.) is more user friendly. The syntax and programs written are readable and understandable with less effort and also require less number of lines to code to solve a problem.
When it comes to C programming language, with the features it provide, it falls in between low and high programming languages. So, it is known as middle level language because it actually binds the gap between a low level language (machine/assembly language) and high level language.
Features of C Programming Language
Some of the features of C Programming are :
- Simple
- Portable (machine independent)
- Fast (Requires relatively fewer machine cycles)
- Pointers
- Recursion
- Extensible
- Function rich libraries
Simple
C programming has a syntax that is very simple to understand and remember.
Portable
Unlike assembly language, c programs can be executed in many machines with little bit or no change. But it is not platform-independent like Java.
Fast
As it can communicate directly with the hardware, the statements of C programming resolve to very few lines of machine code which makes compilation and execution time faster.
Pointers
Pointers will help us to interact with the memory directly. A pointer is a variable which points to the address of the another variable.We can use pointers for memory, structures, arrays, etc.
Recursion
Recursion is the process of repeating items in a self-similar way. Recursion allows you to call a function inside the same function. It provides code re-usability for every function and there are certain problems which could be solved easily through recursion. We shall go through them while we learn recursion in C.
Extensible
C language is extensible because it can easily adopt new features. You can write your own new functions, create a library from those and add to the C language locally.
Function Rich Libraries
C programming is a collection of functions and are supported by C libraries. We can also create our own function and add it to C library.
Applications of C programming
With amazing features that C language has, it attracted a larger developer community and has found applied in many areas of computing and system software. Following are some of those :
- Operating systems
- Development of new programming language
- Computational platform
- Embedded systems
- Graphics and games
C Tutorials
Basics
Input / Output
- C – Read String using scanf()
- C – Read Integer using scanf()
- C – Read Hexadecimal Number using scanf()
- C – Read Float using scanf()
- C – Read a Single Character using scanf()
- C – Read Multiple Values form a Single Line using scanf()
Decision Making
Loops
Operators
- C sizeof
- C Arithmetic Operators
- C Logical Operators
- C Bitwise Operators
- C Relational Operators
Arithmetic Operators
- C Addition Operator
- C Subtraction Operator
- C Multiplication Operator
- C Division Operator
- C Modulus Operator
- C Increment Operator
- C Decrement Operator
Strings
Arrays
- C – Initialize Array
- C – Array Length
- C – Array While Loop
- C – Array For Loop
- C – Sort Array of Integers
- C – Sort Array of Strings
- C – Check if Array contains Specified Element
- C – Find Index of Specific Element in Array
Files
Sorting Programs
- C Program – Bubble Sort
- C Program – Insertion Sort
C Programs
Conclusion
In this C Tutorial, we have seen a brief explanation about the C programming language, its features and some of the real world applications. In our subsequent C Tutorials, we shall dive into setting up the environment for C programming, and basics of C programming.