Brief History of C The C programming language is a structure oriented programming language, developed at Bell Laboratories in 1972 by Dennis Ritchie. C programming language features were derived from an earlier language called “B” (Basic Combined Programming Language – BCPL) C language was invented for implementing UNIX operating system. In 1978, Dennis Ritchie and […]
Programming In C tutorials

Before Moving Ahead with the Programming In C tutorials, Lets have a look at what we will learn in these Topics.
By the end of this Subject, we will be able to learn:
The structure of a C program is a protocol (rules) to the programmer, which he has to follow while writing a C program. The general basic structure of C program is shown in the figure below. Based on this structure, we can sketch a C program. Example: /* This program accepts a number & displays […]
Source File- This file contains the source code of the program. The file extension of any c file is .c. The file contains C source code that defines the main function & maybe other functions Header File- A header file is a file with extension .h which contains the C function declarations and macro definitions […]
Every language has some basic elements & grammatical rules. Before starting with programming, we should be acquainted with the basic elements that build the language. Character Set Communicating with a computer involves speaking the language the computer understands. In C, various characters have been given to communicate. Character set in C consists of; Keywords Keywords […]
Variables are names that are used to store values. It can take different values but one at a time. A data type is associated with each variable & it decides what values the variable can take. When you decide your program needs another variable, you simply declare (or define) a new variable and C makes […]
When we are saying Input that means we 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 […]
Data can be entered & displayed in a particular format. Through format specifications, better presentation of results can be obtained Variations in Output for integer & floats: #include int main() { printf(“Case 1:%6d\n”,9876); /* Prints the number right justified within 6 columns */ printf(“Case 2:%3d\n”,9876); /* Prints the number to be right justified to 3 […]
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C language is rich in built-in operators and provides the following types of operators: • Arithmetic Operators • Relational Operators • Logical Operators • Bitwise Operators • Assignment Operators • Increment and decrement operators • Conditional operators • Misc […]
In C, ++ and – are called increment and decrement operators respectively. Both of these operators are unary operators, i.e, used on single operand. ++ adds 1 to operand and – subtracts 1 to operand respectively. For example: Let a=5 and b=10 a++; //a becomes 6 a–; //a becomes 5 ++a; //a becomes 6 –a; […]
Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator. For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * […]
In C, programs are executed sequentially in the order of which they appear. This condition does not hold true always. Sometimes a situation may arise where we need to execute a certain part of the program. Also it may happen that we may want to execute the same part more than once. Control statements enable […]
while statement The while statement is used when the program needs to perform repetitive tasks. The general form of a while statement is: while ( condition) statement ; The program will repeatedly execute the statement inside the while until the condition becomes false(0). (If the condition is initially false, the statement will not be executed.) Consider the […]
The break Statement The break statement provides an early exit from for, while, and do, just as from switch. A break causes the innermost enclosing loop or switch to be exited immediately. When break is encountered inside any loop, control automatically passes to the first statement after the loop. Consider the following example; main( ) […]
MONOLITHIC VS MODULAR PROGRAMMING: Monolithic Programming indicates the program which contains a single function for the large program. Modular programming help the programmer to divide the whole program into different modules and each module is separately developed and tested. Then the linker will link all these modules to form the complete program. On the other […]
There are four main categories of the functions these are as follows: 1. Function with no arguments and no return values. 2. Function with no arguments and a return value. 3. Function with arguments and no return values. 4. Function with arguments and return values. Function with no arguments and no return values: syntax: void […]
Actual Arguments: 1. Arguments which are mentioned in the function in the function call are known as calling function. 2. These are the values which are actual arguments called to the function. It can be written as constant , function expression on any function call which return a value . ex: funct (6,9) , funct […]
Recursion is a process in which a problem is defined in terms of itself. In ‘C’ it is possible to call a function from itself. Functions that call themselves are known as recursive functions, i.e. a statement within the body of a function calls the same function. Recursion is often termed as ‘Circular Definition’. Thus recursion is the […]
Every repetitive problem can be implemented recursively or iteratively Recursion should be used when the problem is recursive in nature. Iteration should be used when the problem is not inherently recursive Recursive solutions incur more execution overhead than their iterative counterparts, but its advantage is that recursive code is very simple. Recursive version of a problem is slower than iterative […]
To completely define a variable one needs to mention its type along with its storage class. In other words we can say not only variables have a data type but also they have ‘storage classes. Till now the storage class of any variable is not mentioned because storage classes have defaults. If someone doesn’t specify the storage […]
Introduction A data structure is the way data is stored in the machine and the functions used to access that data. An easy way to think of a data structure is a collection of related data items. An array is a data structure that is a collection of variables of one type that are accessed […]
Arrays that we have considered up to now are one dimensional array, a single line of elements. Often data come naturally in the form of a table, e.g. spreadsheet, which need a two-dimensional array. Declaration: The syntax is same as for 1-D array but here 2 subscripts are used. Syntax: data_type array_name[rowsize][columnsize]; Rowsize specifies the […]
1-d arrays using functions Passing individual array elements to a function We can pass individual array elements as arguments to a function like other simple variables. Example: #include <stdio.h> void check(int); void main() { int a[10],i; clrscr(); printf(“\n enter the array elements:”); for(i=0;i<10;i++) { scanf(“%d”,&a[i]); check(a[i]); } void check(int num) { if(num%2==0) printf(“%d is even\n”,num); else […]
A string is a series of characters treated as a single unit. A string may include letters, digits and various special characters such as +, -, *, / and $. String literals or string constants in C are written in double quotation marks as follows: “1000 Main Street” (a street address) “(080)329-7082” (a telephone number) “Kalamazoo, New […]
strcpy(): It is used to copy one string to another string. The content of the second string is copied to the content of the first string. Syntax: strcpy (string 1, string 2); Example: char mystr[10]; mystr = “Hello”; // Error! Illegal !!! Because we are assigning the value to mystr which is not possible in case of […]
Definition A Structure is a user defined data type that can store related information together. The variable within a structure are of different data types and each has a name that is used to select it from the structure. C arrays allow you to define type of variables that can hold several data items of the same kind […]
The structure that contains another structure as its members is called a nested structure or a structure within a structure is called nested structure. The structure should be declared separately and then be grouped into high level structure. Passing Structures through pointers Pointer to a structure is a variable that holds the address of a structure. The […]
Union is a collection of variables of different data types, in case of union information can only be stored In one field at any one time. A union is a special data type available in C that enables you to store different data types in the same memory location. You can define a union with many members, but […]
A pointer is a variable that contains the address of a variable. Pointers are much used in C, partly because they are sometimes the only way to express a computation, and partly because they usually lead to more compact and efficient code than can be obtained in other ways. Pointers and arrays are closely related; this chapter […]
In C, there is a strong relationship between pointers and arrays, strong enough that pointers and arrays should be discussed simultaneously. Any operation that can be achieved by array subscripting can also be done with pointers. The pointer version will in general be faster but, at least to the uninitiated, somewhat harder to understand. The declaration int a[10]; defines an […]
If p is a pointer to some element of an array, then p++ increments p to point to the next element, and p+=i increments it to point i elements beyond where it currently does. These and similar constructions are the simples forms of pointer or address arithmetic. All types of arithmetic operations are not possible with pointers. The […]
How to declare a pointer to a function? Syntax: returntype_of_function (*pointer variable)(List of arguments); For example: int (*p)(int,int); can be interpreted as p is a pointer to function which takes two integers as argument and returntype is integer. How to make a pointer to a function? Syntax: pointer_variable=function_name_without_parantheses; For Example: p=test; can be read as p is […]
The memory allocation that we have done till now was static memory allocation.. So the memory that could be used by the program was fixed. So we could not allocate or deallocate memory during the execution of the program. It is not possible to predict how much memory will be needed by the program at […]
You may recall that the name of an array stands for the address of its zero-th element. Also true for the names of arrays of structure variables. Consider the declaration: struct stud { int roll; char dept_code[25]; float cgpa; } class[100], *ptr ; The name class represents the address of the zero-th element of the structure […]
A File is a collection of data stored on a secondary storage device like hard disk. File operation is to combine all the input data into a file and then to operate through the C program. Various operations like insertion, deletion, opening closing etc can be done upon a file. When the program is terminated, the entire data […]