c language, c programming, c programming language, c tutorial, learn c programming
Introduction of C Language
In 1960, The Cambridge university was introduced a programming language called BCPL (Basic Combined Programming Language). It is also called a ‘B’ Language. After that ‘B’ Language was modified by “Dennis Ritchie” in 1972 at AT&T Bell Lab’s. The New language named called ‘C’ language. In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, known as the K&R standard. Then C language
has now become a widely used professional language for various reasons.
is used to mathematical, business and scientific environments. Every language supports some pre-defined functions and keywords. Using those functions and keywords we can write any type of program statements.
C language is one of most popular language in today’s programming language.
A program is a group of statements or set of instructions.
If we want to perform some task we can write some statements based on that find out the result.
Characteristics of C Language
- Easy to learn
- Structured language
- Powerful programming language
- It can handle low-level activities.
- It produces efficient programs.
- It can be compiled on a variety of computer platforms.
C Program Structure
In a basic C program structure the following things are involved.
- Preprocessor declaration (Header files, etc.)
- User-defined function prototype declaration (if any)
- Global variable declaration (if any)
- Main function body
- User-defined function body (only declared function bodies are build here)
A simple structure read more…
C Basic Syntax
To write a c program you must have a basic knowledge of C syntax’s. You have seen a basic structure of C program, so it will be easy to understand other basic building blocks of the C programming language Read more…
C Data Types
Basic data types in the c language are character, integer, floating point and double floating point. These are declared as char, int, float and double respectively. The size and range of these data types may vary based on processors and compilers.
Basic data types may have various modifiers preceding them. A type modifier alters the meaning of the base type to more precisely fit a specified need. The list of modifiers is as follows Read more…
A variable is a named location in memory that is used to hold a value of a particular data type that value can be changed by program. Every variable has a name and value. There are limitations on what should be variable name. A variable name must satisfy the following Read more…
C Constants and Literals
A constant is fixed values which cannot change the meaning of value during program execution. These fixed values are also called literals
Constants can be of any of the basic data types like an integer constant
, a floating constant, a character constant,
or a string literal.
There are also enumeration constants as well.
The constants are treated actually like standard variables aside from that their qualities can’t be altered after their definition. It is considered best practice to define constants using only upper-case
In C Constants are categorized into two basic types and each of these types has its subtypes. Those are: Read more…
C Storage Classes
A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program. These specifiers precede the type that they modify. There are the following storage classes, which can be used in a C Program
An Operator is a symbol it tells the compiler either do mathematical and logical calculations. Operators are performing to any calculations on variables. We have already seen some operators + – * / and so on. In C Language operators are dividing into the following categories.
- Arithmetic Operators.
- Relational Operators.
- Logical Operators.
- Conditional Operator.
- Assignment Operator ( = )
- Increment and decrement operators.
- Bitwise operator.
- Other Operators.
Decision Making in C
Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
Programming languages provide various control structures that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages
Function is a group of statements that together perform a task. A function is also called as method or a sub-routine or a procedure, etc.
C Scope Rules
A scope in any programming is a region of the program where a defined variable can have its existence and beyond that variable cannot be accessed. There are three places where variables can be declared in C programming language.
Inside a function or a block which are called local variables
In the definition of function parameters which is called formal parameters.
Outside of all functions which are called global variables.
Array is a collection of similar data items or elements or we can say array is a collection of homogeneous data elements stored continuously under a single name. When there are number of variables with same type and nature then it is difficult to handle them, so we need array.
Pointer in C language is a variable which holds the address of another variable of same data type. Pointers are used to access memory and manipulate the address. Pointers are one of the most distinct and exciting features of C language.
String in C programming language is actually a one-dimensional array of characters which is terminated by a null character ‘\0’. Thus a null-terminated string contains the characters that comprise the string followed by a null.
A structure is a meaningful collection of data items of different type. But it collects all elements under a unique name. A structure allows the programmer to create and manipulate a set of different types of data items. In C, all the data items can be grouped together in one structure using the keyword struct.
A union is a user-defined type similar to structs in C programming. It is a special data type available in C that allows storing different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple-purpose. We recommend you to learn C structs before you check this tutorial.
Bit field can be used to reduce memory consumption when it is known that only some bits would be used for a variable. Bit fields allow efficient packaging of data in the memory.
The C programming language provides a keyword called typedef, which you can use to give a data type a new name.
Input & Output
When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming language provides a set of built-in functions to read given input and feed it to the program as per requirement.
When we are saying Output that means to display some data on screen, printer or in any file. C programming language provides a set of built-in functions to output the data on the computer screen as well as you can save that data in text or binary files.
A file represents a sequence of bytes, does not matter if it is a text file or binary file. C programming language provides access on high level functions as well as low level (OS level) calls to handle file on your storage devices. This chapter will take you through important calls for the file management.
The C Pre-processor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do require pre-processing before the actual compilation.
A header file is a file with extension “.h” which contains C function declarations and macro definitions and to be shared between several source files. There are two types of header files:
Predefined: The files that comes with the compiler.
User-defined: The files that the programmer writes.
Type casting is a way to convert a variable from one data type to another data type. For example, if you want to store a long value into a simple integer then you can type cast long to int. You can convert values from one type to another explicitly using the cast operator.
As such C programming does not provide direct support for error handling but being a system programming language, it provides you access at lower level in the form of return values.
Recursion is the process of repeating items in a self-similar way. Same applies in programming languages as well where if a programming allows you to call a function inside the same function that is called recursive call of the function.
Sometimes, you may come across a situation, when you want to have a function, which can take variable number of arguments, i.e., parameters, instead of predefined number of parameters. The C programming language provides a solution for this situation and you are allowed to define a function which can accept variable number of parameters based on your requirement.
The C programming language provides several functions for memory allocation and management. These functions can be found in the<stdlib.h> header file.
Command Line Arguments
It is possible to pass some values from the command line to your C programs when they are executed. These values are called command line arguments and many times they are important for your program specially when you want to control your program from outside instead of hard coding those values inside the code.