C Programming Language

This tutorial covers basic concepts of  C. Topics covered are Basics of C, Constants, Data  types, Operators, Control Structures, Arrays, Functions, pointers, structure, union, data file handling, characters and strings along with different libraries.

Lessons

Introduction to C Language

Preview

Complexity: Standard

Introduction to C Language C Language is a high level programming language developed at “AT & T’s Bell Laboratories”, USA in 1972. It was written by Dennis Ritchie and Brian Kernighan. It  is also known as middle level language as it has inbuilt support for writing programs using assembly language instructions. This language was created …

What is a variable in C Language

Preview

What is a variable in C Language A variable may be defined as a named memory location i.e. a variable is the name given to a data item to refer to a memory location. The value of a variable can vary during the execution of a program. Rules to name a variable in C Language …

Constants in C Language

Preview

Complexity: Standard

Constants in C Language A Constant may be defined as a quantity whose value can’t be changed during the execution of a program. Constant can be divided into two categories. Numeric Constant Character Constant/Non Numeric Constant Numeric Constant Numeric Constant is that which can contain digits in it. Numeric constant can be categorized into two …

Data Types in C Language

Preview

Data types in C Language Data type is the way to specify the type of data as well as the range of values that can be stored in the data object or a variable. C supports three types of data types:- Primary Data Types Derived Data Types User Defined Data Types Primary Data Types Primary …

Display output in C – printf() function

Preview

Display output in C- printf() function To Display output in C, we need to use printf() function. It is also known as formatted output function. Formatted output means the output which is arranged in a particular format. The syntax of printf function() is: printf(“Control string”, arg1,arg2……); Control string specifies the format in which data is …

Read values in C- scanf() function

Preview

Read values in C- Formatted Input Formatted input means the input which is arranged in a specific format. For formatted input, scanf() function() is used. The syntax of scanf function() is: scanf(“Control string”, arg1,arg2……); Control string specifies the format in which data is to be entered by the user while inputting. Control string consists of …

C – Unformatted Output Function

Preview

C – Unformatted Output Function There are  various output functions provided by C Language. These functions are used to display the value of a variable during the execution of program. Various unformatted output functions provided by C Language are as follows:  1. putchar() It stands for put character. It is used to display value of …

C – Unformatted Input Function

Preview

Complexity: Standard

C – Unformatted Input function There are various input functions provided by C Language. These functions are used to read the value of a variable during the execution of program. Various unformatted input functions provided by C Language are as follows: 1. getchar() It stands for get character. It is used to read value of …

4 Types of Operators in C

Preview

Operators These are the symbols which are used to perform some calculation or manipulation on values which may be in the form of variables, constants or expressions in a C program. Operand It is the variable, constant or expression on which an operator performs some calculation, comparison or some other manipulation. Example    6+5       …

Increment Decrement Operators in C (++ / –)

Preview

1. Increment Operator (++) Increment operator is represented as ++. This operator is used to add one to the existing value of a variable. The variable can be of any data type including integer, real as well as character data type. It can be used in two ways:- Prefix Form In this form, the increment …

Arithmetic Operators in C

Preview

Arithmetic Operators in C Arithmetic operators are used to perform mathematical calculations in a program. Various arithmetic operators in C language are as follows: + [Addition Operator] – [Subtraction Operator] * [Multiplication Operator] / [Division Operator] % [Modulus Operator] 1. + Addition operator is represented as plus (+) sign. It is used to add values …

Relational Operators in C | Comparison operators in C

Preview

Relational Operators in C These operators are used to perform comparison between values in a program. The result of relational expression is always 0 or 1. Various relational operators in C language are as follows: < [Less Than] <= [Less Than Equal To] > [Greater Than] >= [Greater Than Equal To] = = [Equal To] …

Logical Operators in C

Preview

Logical Operators in C These operators are used to combine relational expressions. The Output: of a logical expression is always 1 or 0. Various logical operators in C language are as follows: Operator Name of Operator Purpose && Logical AND To combine two relational expressions. If any of the input is 0, Output: would be …

Bitwise operators in C | Bitwise Operator programs in C

Preview

Bitwise operators in C Bitwise operators are used to manipulate individual bits of a numeric value. There are six bitwise operators provided by C language. Bitwise AND(&) Bitwise OR (|) Bitwise XOR(^) Bitwise complement(~) Bitwise Left shift(,) Bitwise Right shift(>>) **Bitwise form of a number is obtained by converting the number into binary number. 1. …

Assignment Operators in C | Shorthand operators in C

Preview

Assignment operators in C Assignment/shorthand operators are used to update the value of a variable in an easy way. There are various assignment operators provided by C language. = += -= *= /= %= &= |= ^= <<= >>= Operator Description Example = It is used to assign some value to a variable. A=10 += …

Conditional operator in C | Ternary Operator in C

Preview

Conditional operator in C Conditional operator is also known as ternary operator. This operator is known as ternary operator because it has three operands. Ternary operator is represented as ?: . It is used to check a condition and depending upon the condition, particular instruction is executed by the compiler. Syntax: Condition? Block1: Block2; Condition …

sizeof() operator in C | comma operator in C

Preview

Special operators These operators are used for special purposes. There are many special operators provided by C language which are as follows:  sizeof()  Comma 1.  sizeof() This operator is used to find the size of a variable, constant or data type. The size returned by this operator is in terms of bytes. Program to demonstrate …

Implicit type Conversion in C | Automatic type conversion in C

Preview

Implicit type Conversion in C | Automatic type conversion in C Implicit conversion means automatic conversion. It is the way in which the output of an arithmetic expression is converted automatically into a particular data type. The basic rule of implicit conversion is that the output of an expression will be of that data type …

Explicit type conversion in C | Casting in C

Preview

Explicit type conversion in C | Casting in C It is the way to convert the output of an arithmetic expression into a data type specified by the programmer. It is basically used to change implicit conversion. The syntax of casting is: (Type) Expression type refers to any valid data type of C language in …

Precedence and Associativity of Operators in C | Expressions in C

Preview

Precedence and Associativity of Operators in C Precedence is the way to provide a priority to every operator. When more than one operator appear in an expression, they will be evaluated depending upon their precedence i.e. the operator with higher precedence will be evaluated first followed by the operator with lower precedence and so on. …

Control Structures in C | Control statements in C

Preview

Control Structures in C Control structure is also known as a control statement. Control structure is any statement of C language which can be used to control the flow of statements in a C program. By default, instructions in a program get executed in the same sequence in which they are written. Control structure can …

Simple if statement in C language

Preview

If Statement in C Language If statement is a very powerful decision making statement and it is used to control the flow of execution of statements. It is basically a two way decision making statement and it is used with a relational or logical expression. There are four types of if statement: Simple if If …

if else statement in C language

Preview

if else statement in C language  It is two way decision making  statement. In if else statement, there is only one condition and depending upon the condition, a particular set of statements will be executed. If  condition is true, one set of statements will be executed otherwise another set of statements will be executed Syntax …

Nested if statement in C Langauge

Preview

Nested if statement in C Langauge It is basically a multiway decision making statement. In nested if statement, one if statement is enclosed within another if statement. Depending upon these if statements, particular set of statements will be executed. The syntax of nested if statement is: if(Condition1) {             if(Condition2)             Statement-Block1;             else                  …

if else if ladder statement in c language

Preview

if else if ladder statement in c language This is most commonly used selection statement in C language.  It is basically a multi way decision making statement. In if else if ladder statement, there are multiple conditions one after another. Depending upon these conditions, specific sets of statements are executed. The syntax of if else …

switch statement in C | Working of switch statement in C

Preview

 Switch statement Switch statement is a multi-branch selection statement. Switch statement works with a variable or expression known as control variable or control expression. Switch tests the value of control expression/variable with a list of values known as cases of switch statement. When the value of control expression/variable matches with any of the case value, …

for statement in c language | Nesting of for in c language

Preview

for statement in c language for statement is a looping statement of c language. Looping statements are also known as iterative statements. Looping statements are used to repeat same set of statements again and again depending upon a condition. for statement is an entry controlled looping statement. It is basically used when we clearly know …

while statement in c language

Preview

while statement in c language It is an entry controlled looping statement. It is basically used when we may not be aware of how many times the loop will execute. In while statement, initialization, condition and updation are performed in different lines. The syntax of while statement is: Initialization; while(Condition) { Statement-Block; Updation; } Statement-X; …

do while statement in c

Preview

do while statement in C It is an exit controlled looping statement. It is basically used when we want that loop should execute at least once. In do while statement initialization, condition and updation are performed in separate lines. The syntax of do while statement is: initialization; do { Statement-Block; updation; } while(Condition); Statement-X; do …

Jumping statements in C

Preview

Jumping Statements in C Jumping statements are used to transfer the control of program from one point to another within the program. There are three types of jumping statements provided by C language. break continue goto exit  1. break break is a keyword of C language. It is used with switch and looping statements. It …

Introduction to characters in C

Preview

Introduction to characters in C A character constant is a single characters enclosed in single quotes (‘). A character constant can contain an alphabet, digit, special character or a white space. A character constant can’t contain more than one character in it. Example ‘Z’ , ‘9’ , ‘#’ etc. Character Variable A character variable is …

Character functions in C

Preview

Character functions in C There are various character functions provided by C Language to check or change the case of value of a character variable or a character constant. We need to include header file ctype.h in our program to use these functions in our program. Various character functions are: isalpha() isdigit() isalnum() ispunct() isspace() …

Strings in c language with examples

Preview

Strings in c language with examples A string is a group of one or more characters enclosed within double quotes (“). A string can alphabets, digits , special characters and blank spaces. A string is always terminated with a special character called null character represented as ‘\0’. Example:  “Lovejot” , “2019” , “Rs4000”,  “ladderpython@gmail.com”  1. …

 String functions in c language with examples | strcpy, strcat, strcmp, strrev, strlen

Preview

 String functions in c language with examples There are various string functions which we can use in C Language. We need to include header file string.h in our program to use these functions in our program. Various string functions in c language are: strcpy() strncpy() strcat() strlen() strrev() strcmp() strcmpi() strncmp() strlwr() strupr() 1. strcpy() …

Array of strings in c language with examples

Preview

Array of strings in c language with examples It is actually a two dimensional array of char type. Example: char names[6][30]; In above example, names is an array of strings which can contain 6 string values. Each of the string value can contain maximum 30 characters. 1. Initialization of array of strings We can initialize an …

Introduction to Array in C | One dimensional array in C

Preview

Introduction to Array in C Array is a collection of homogeneous elements having same data type and same Size. All the elements of an array are stored in consecutive memory locations. All the elements of an array are referenced by a single name. Each individual element of any array can be processed using index of …

Two dimensional array in C | Initialization of Two dimensional array in C

Preview

Two dimensional array in C Array having two dimensions is known as two dimensional array. We use two subscripts to specify the size of a two dimensional array or to refer to any element of the two dimensional array. A two dimensional array is also known as a matrix and elements of two dimensional array …

Multi dimensional Array in C

Preview

Multi dimensional Array in C Array having more than two dimensions is known as multi-dimensional array. The limit of dimensions in a multidimensional array is specified by the compiler. It may depend upon the size of main memory available in computer.  We can use more than two subscripts to specify the size of a multidimensional …

Introduction to function in C Language

Preview

Introduction to function in C Language Function is defined as the named group of statements which can be used to perform a specific task. A function can contain one or more valid C language statements.  When we call a function, all the statements written within the function are executed on after another. Advantages of a …

Types of function in C Language

Preview

Types of function in C Language A function can be categorized into two categories: Library Function User Defined Function 1. Library Function It is a predefined function provided by C Language programming language. Library functions exist in header files i.e. their definitions lie in header files. These functions are used to perform basic input/output operations, …

Arguments passing in C | Call by value | Call by reference

Preview

Arguments passing in C Arguments can be passed to a function in two ways: Call by value Call by reference Call by Value It is also termed as passing arguments by value. In this case, the values of actual arguments are copied to formal arguments on one to one basis in function definition and any …

Recursion in C | Programs of recursion in c

Preview

Recursion in C It is the process in which a function repeatedly calls itself. It should be noted that during recursion we must specify some condition with which the function will stop execution. If we don’t specify any condition, the program will go on until the run time stack overflows. Recursion function can be used …

Scope of variable in C | Local variable in C | Global variable in c

Preview

Scope of variable in C Scope is defined as the lifetime of a variable. It specifies how long a variable will exist in the program and in what parts of a program, it will be available. Variables are categorized into two categories depending upon their scope. Local variables Global variables  a.  Local variable  in C …

Storage class in C | auto , register, extern, static

Preview

Storage class in C Storage class is basically used to specify the scope and lifetime of a variable. It specifies the place where the variable may be stored i.e. memory or CPU registers. It also specifies the initial value of a variable, if the initial value is not specified in the program. It also specifies …

Introduction to pointer in C | pointer operations in C

Preview

Introduction to pointer in C Pointer is way to refer to a memory location. A pointer variable is a variable which can contain the address of another data item which may be a variable or an array. A variable has three basic properties including its name,  value and  memory location. Suppose we declare an integer …

Pointer with Array in C

Preview

Pointer with Array in C Arrays are directly associated with pointers as arrays are internally implemented with the help of pointers. Compiler needs to know about the address of very first element of array. Addresses of rest of the elements are automatically calculated on the basis of first element’s address in memory. Pointer and One …

Pointer with Strings in C

Preview

Pointer with Strings in C In C language, a string is represented as a character array. When we declare a string, we need to specify size of string just as we do  in arrays. Example char sname[14]; In this example sname is a string variable which can contain maximum 14 characters including null character. So …

Pointer with function in C | Pointer to function in C

Preview

Pointer with function in C We can use pointers with functions in following ways: Passing function arguments by reference In this case, the addresses of actual arguments are stored in formal arguments in function definition and any changes made to the formal arguments in the function body are reflected back to the calling function and …

void type pointer

Preview

void type pointer Just like other data types, we can declare a pointer variable of void type. In case of other data types, the data type of pointer variable and the variable whose address is to be stored in pointer variable must be same but in case of void type pointer variable, address of variable …

Pointer to pointer in c

Preview

Pointer to pointer C language allows us to take pointer variables which can contain address of other pointer variables. In such a case, the concept of pointer to pointer is used. The pointer to pointer variable can be declared by prefixing the variable declaration with double asterisk sign. Example int **a; Here, pointer variable a …

Dynamic memory allocation in C

Preview

Dynamic memory allocation in C C language offers various functions to allocate and de-allocate memory to variables at run time. Various functions for performing these functions are; malloc() calloc() free() 1. malloc() function malloc() is a predefined function provided by C language which is used to dynamically allocate memory to variable at run time. malloc() …

Introduction to Structure in C

Preview

Introduction to Structure in C Structure is a user defined data type provided by C language. It is a collection of heterogeneous types of elements i.e. it is a collection of different data types, size and range. It is a tool for handling a group of logically related data items. For example, we can use …

Nesting of Structure in C

Nesting of Structure in C It is the process of defining one structure within another structure. Nesting of structure can also be applied by taking variable one structure within another structure. The main advantage of performing nesting is that we can use an existing structure without need to create a new structure for same requirements. …

Array of structure type | array within structure

Preview

We can use arrays with a structure in many ways: 1. Array of Structure type Just like array of basic data types, we can also declare an array of structure type. The main feature of structure type array is that all the members of structure are associated with each and every element of structure. The …

Structure type arguments in C

Preview

Structure type arguments in C  We can pass structure type variables as arguments to functions. There are three methods in which structure type argument can be passed to a function. Passing each element of structure variable independently. Passing structure type argument by value(Call by Value) Passing structure type argument by reference(Call by Reference) Passing each …

Function returning structure in C

Preview

Function returning structure in C We can make return type of any function to be a structure. The very main thing to be noted in this case is that the function must be returning the variable of structure type. Program to specify a structure as the return type of function. #include<stdio.h> struct data { int …

Structure with Pointers in C

Preview

Structure with Pointers in C Just like other data types, we can also declare pointer variables of a structure.  The syntax for declaring a structure type pointer variable is: struct Struct_name  *Struct_pointer; Struct_pointer refers the name of pointer variable of structure type. We can access structure elements through its pointer variable in two ways: Using …

Self Referential Structure

Preview

Self Referential Structure It is a special type of structure which contains a member of its own type. The member of its own type is actually a pointer variable of same structure in which it is declared. Self referential structure is basically used for implementation of a linked list in C language. Example struct node …

Introduction to Union

Preview

Introduction to Union It is similar to a structure but processing and storage is different. Union can also contain different types of elements having different data types. The main difference between a structure and a union is that all the members of a structure have different memory locations whereas all members of a union share …

Data File Handling in C

Preview

Data File Handling in C File is a collection of logically related data. It is the way to store data permanently on computer so that we can retrieve and use it later. A file can also be defined as a collection of bytes stored on some storage device like hard disk, CD, DVD etc. Why …

Steps to create a data file in C

Preview

Steps to create a data file in C Declaring a file pointer Opening a file Reading or writing data in the file Closing the file 1. Declaring a file pointer A file must be open before any I/O operation can be performed on that file. A predefined structure named File is defined in the stdio.h …

File Input output in C

Preview

File Input output in C There are many functions provided by C language to read or write data into a file. These include the following functions: 1.  fputc() function fputc() function is used to write a single character to a specified file at the current file position and then increment the file position pointer. The …

Random Access of Files in C

Preview

Random Access of Files in C In C language, we can randomly position file pointer at a particular position in the file and can perform reading and writing of data at that particular position. There are two predefined functions provided by C language to randomly position the file pointer at a particular position in the …

Command Line Arguments in C

Preview

Command Line Arguments in C In C language, it is possible to accept command line arguments. Command-line arguments are providing by typing name of program followed by arguments at command prompt. To use command line arguments in our program, we must declare the main() function which accepts two arguments as follows: First argument specifies the …