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

Length: 0 minutesComplexity: 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. Features of C Language C is a robust language having built-in functions, data types and operators to write complex programs. C Language is a …

What is a variable in C Language

Preview

Length: 0 minutes

What is a variable in C Language A variable may be defined as a named memory location. The value of a variable can vary during the execution of a program. Rules to name a variable in C Language There are few basics rules which must be kept in mind while defining a variable. They are …

Constants in C Language

Preview

Length: 0 minutesComplexity: 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 following categories. 1. Numeric Constant Numeric Constant can contain digits in It can be categorized into two types: Integer Constant Floating point Constant/Real Constant 1. Integer Constant …

Data Types in C Language

Preview

Data types in C Language Data type is the way to specify the type of data and range of values that can be stored in a variable. C supports three types of data types:- Primary Data Types Derived Data Types User Defined Data Types Primary Data Types There are four primary data types provided by …

Display output in C – printf() function

Preview

Length: 0 minutes

Display output in C- printf() function in C Language printf() function is used to display output in C. Syntax of printf function() is: printf(“Control string”, arg1,arg2……); Control string specifies the format to enter the data. arg1,arg2,….. are constants, expression or variables whose values should be displayed. 1. print int type data in C Language Format …

Read values in C- scanf() function

Preview

Length: 0 minutes

Read values in C- scanf() function in C scanf() function() is used to read different types of values in C. Syntax: scanf(“Control-string”, &arg1,&arg2,&arg3,……); Control-string is the format to enter data. It has % sign followed by format specifier indicating the type of variable whose value is to be input . &arg1,&arg2,&arg3,… refer to variables whose …

C – Unformatted Output Functions

Preview

Length: 0 minutes

C – Unformatted Output Functions Unformatted output functions provided by C are :  1. putchar() function in |C This function is used to display value of a character variable or constant. The header file required is <stdio.h>. Syntax: putchar(var); var refers to the character variable or character constant whose value we want to display using putchar() …

C – Unformatted Input Functions

Preview

Length: 0 minutesComplexity: Standard

Unformatted Input functions in C Language Various unformatted input functions provided by C are: 1. getchar() It is used to read value of a character variable. While using this function, we need to assign this function to the character variable whose value we want to read. The header file required for this function is <stdio.h>. …

4 Types of Operators in C

Preview

Length: 0 minutes

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       …

Arithmetic Operators in C

Preview

Length: 0 minutes

Arithmetic Operators in C Arithmetic operators are used to perform mathematical calculations in a program. Various arithmetic operators in C language are as follows: 1. + Addition operator is represented as plus (+) sign. It is used to add values of numeric variables, constants or expressions. Example 11 + 3 = 14 2. – Subtraction …

Relational Operators in C | Comparison operators in C

Preview

Length: 0 minutes

Relational Operators in C | Comparison operators in C These operators are used to perform comparison between values . Various relational operators in C language are as follows:  1. < [Less Than] Less Than operator is represented as (<) sign. It is used to check whether one value is smaller than another value or not. …

Assignment Operators in C | Shorthand operators in C

Preview

Length: 0 minutes

Assignment Operators in C | Shorthand 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 = It is used to assign some value to …

Conditional operator in C | Ternary Operator in C

Preview

Length: 0 minutes

Conditional operator in C | Ternary Operator in C Conditional operator/ternary operator has three operands. It is represented as ?: . It tests a condition and depending upon condition, specific  instruction gets executed . Syntax: Condition? Statement: Statement2; Condition represents a condition made using relational or logical operators. Statement1 represents the statement to be executed …

sizeof() operator in C | comma operator in C | Special operators in C

Preview

Length: 0 minutes

sizeof() operator in C | comma operator in C | Special operators in C There are many special operators provided by C language which are as follows:  sizeof()  Comma 1.  sizeof() operator in C This operator returns the size of a variable, constant or data type in terms of bytes. Program to demonstrate the use …

Implicit type Conversion in C | Automatic type conversion in C

Preview

Implicit type Conversion in C | Automatic type conversion in C It is the predefined method of C due to which, the output of an arithmetic expression is converted into a particular data type.  Rule says that output of expression will be of data type having highest number of bytes and range. For example In …

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 specific data type. The syntax of casting is: (Data_Type) Arithmetic_Expression Data_Type is any data type of C in which we want to convert the output of an expression. Arithmetic_Expression is any arithmetic …

Precedence and Associativity of Operators in C | Expressions in C

Preview

Precedence and Associativity of Operators in C Precedence is the priority assigned to operators. When more than one operator appears in an expression, they will be evaluated as per their precedence. In expression 10+6/2, division operator (/) has more priority than addition operator (+), so 6/2 will be evaluated followed by adding 10 the the …

Simple if statement in C language

Preview

Length: 0 minutes

Simple if statement in C language Simple if statement in C language is a very powerful decision making statement and it is used to control the flow of execution of statements. There are four types of if statement: Simple if If else Nested if If else if ladder Simple if statement in C language  In …

if else statement in C language

Preview

Length: 0 minutes

if else statement in C language  It is a two way decision making statement. In if else statement, there is only one condition. If  condition is true, one set of statements will be executed otherwise another set of statements will be executed. Syntax of if else statement is: if(TestCondition) {   Block1; } else { …

Nested if statement in C Language

Preview

Length: 0 minutes

Nested if statement in C Language In nested if statement, one if statement block is enclosed within another if statement block. The syntax of nested if statement is: if(TestCondition-1) {             if(TestCondition-2)              Block-1;             else                  Block-2; } else {             if(TestCondition-3)     …

if else if ladder statement in c language | ladder if statement in C

Preview

Length: 0 minutes

if else if ladder statement in c language | ladder if statement in C 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 if ladder statement is: …

switch statement in C | Working of switch statement in C

Preview

Length: 0 minutes

switch statement in C | Working of switch statement in C It is a multi-branch selection statement that works with a variable or expression whose value is compared with a list of values known as cases of switch statement. If  value of expression/variable matches with any of the case value, the block of statements associated …

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

Preview

for statement in c language | Nesting of for in c language | for loop in C for statement is a looping statement used to repeat a set of statements for a specified number of times. Syntax of for statement is: for(Initialize;Condition;Update) { Statements; } for is a predefined keyword of C Language . Initialize …

while statement in C++ | while loop in C++

Preview

Length: 0 minutes

while statement in C++ | while loop in C++ 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) { …

while statement in C language | while loop in C language

Preview

Length: 0 minutes

while statement in C language | while loop 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; …

do while statement in c | do while loop in C

Preview

do while statement in C | do while loop in C In do while statement initialization, condition and updation are performed in separate lines. This looping statement executes at least once. The syntax of do while statement is: Initialization; do { Statements; updation; } while(Condition); do is a keyword which specifies that do while statement …

Introduction to characters in C

Preview

Length: 0 minutes

Introduction to characters in C Character Constant: Character constant is a single characters enclosed within the pair of single quotes (‘). It can contain any alphabet, digit, special character as well as space. We can’t store more than one character in it. Example ‘A’ , ‘5’ , ‘$’ etc. Character Variable Character variable is a …

Character functions in C

Preview

Length: 0 minutes

Character functions in C Character functions need ctype.h  header file to be included in the pgoram. Different character functions provided by C Language are: 1.  isalpha(): This function checks whether the character variable/constant contains alphabet or not.   2. isdigit() This function checks whether the character variable/ constant contains digit or not. 3. isalnum() This …

Array of strings in c language with examples

Preview

Length: 0 minutes

Array of strings in c language with examples | String array in C Language 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 …

Introduction to Array in C | One dimensional array in C

Preview

Introduction to Array in C Language Array is a collection of values having same data type and size. Elements of array are internally stored in consecutive locations. We can access individual elements of array by using index of array elements where index is an integer value starting from 0. Types of Array in C Language …

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

Preview

Two dimensional array in C | Initialization of Two dimensional array in C Two dimensional array is an array whose elements are represented in the form of rows and columns. The syntax for declaring a two dimensional array is: <Type> Array_name[ROW][COL]; Type refers to data type of array like int, float, char etc. Array_name  is …

Multi dimensional Array in C

Preview

Multi dimensional Array in C Language An array containing more than two dimensions is called multi-dimensional array. We can use more than two pairs of brackets to specify the size or refer any array element Syntax : <Data_Type> Array_name[s1][s2][s3]……………….; s1,s2,s3,…. specify the dimensions in the multidimensional array. They should be integer values. Program of  multi …

Introduction to function in C Language

Preview

Introduction to function in C Language It is defined as named block of statements . Advantages of function in C Language It is very easy to find and correct errors . It reduces complexity . Testing becomes easier. Bigger problems can be divided into smaller sections . They can be reused. Simple to understand a …

Types of function in C Language | Function types in C Language

Preview

Types of function in C Language  | Function types in C Language A function is categorized into two types: 1. Library Functions in C Language These are predefined functions that exist in header files of C Language.  These are meant for input/output, complex mathematical functions and various other tasks. 2.  User Defined Function in C Language …

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

Preview

Length: 0 minutes

Arguments passing in C | Call by value in C | Call by reference in C Arguments can be passed to a function in two ways: Call by value Call by reference Call by Value in C Language In this method, values of actual arguments get copied to formal arguments one to one basis.  Changes …

Recursion in C Language | Programs of recursion in C Language

Preview

Length: 0 minutes

Recursion in C Language | Programs of recursion in C Language Function repeatedly calling itself is called recursion. We must specify some condition to stop recursion  otherwise function may run infinitely.  Program using recursion to find factorial of a number . #include<stdio.h> int factorial(int no) { if(no==1||no==0) return(1); else return(no*factorial(no-1)); } int main() { int …

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

Preview

Length: 0 minutes

Storage classes in C Language | auto , register, extern, static in C Language Storage class specifies the scope of a variable in a program. It specifies the whether the variable will be stored in RAM or registers. It specifies which parts of a program can access the variable and how long the variable stays …

Pointer with Strings in C Language | String pointer in C Language

Preview

Length: 0 minutes

Pointer with Strings in C Language | String pointer in C Language A string variable can be declared using pointer as: char *name; name is a string variable that can hold any number of characters in it and there is no wastage of space as size will be automatically adjusted  depending upon the number of …

Pointer with function in C | Pointer to function in C

Preview

Length: 0 minutes

Pointer with function in C We can use pointers with functions in following ways: Function returning pointer In C language, a function can even return a pointer like other data types. The syntax for function returning a pointer is: Data_type *fun_name(Arguments); Program to demonstrate a function returning pointer #include<stdio.h> int *sum(int a,int b) { int …

void type pointer in C Language | using void pointer in C

Preview

Length: 0 minutes

void type pointer in C Language | using void pointer in C In C language we can also declare a void type pointer variable. void type pointer variable can contain address of variable of any other data type . Program of void pointer. #include<stdio.h> int main() { int var1=20; void *var2; var2=&var1; printf(“var2=%u”,var2); return(0); } …

Pointer to pointer in c

Preview

Length: 0 minutes

Pointer to pointer in C  Language A pointer variable in C language can also contain address of another pointer variable. This concepts is called pointer to pointer. We can declare a pointer to pointer as: int **ptr; Here, ptr is a pointer to pointer. Program of pointer to pointer in C #include<stdio.h> int main() { …

Dynamic memory allocation in C

Preview

Length: 0 minutes

Dynamic memory allocation in C We can dynamically allocate and de-allocate memory to variables in C language.  Different functions for dynamic memory allocation/de-allocation are: malloc() free() 1. malloc() function malloc() is a predefined function of C language that can dynamically allocate memory to variables. It allocates a block of fixed size block from memory. Header …

Nesting of Structure in C

Length: 0 minutes

Nesting of Structure in C Defining one structure within another structure. is known as  nesting of structure. We can do it as follows:   Program to demonstrate nesting of structure. #include<string.h> #include<stdio.h> struct dob { int dd; int mm; int yy; }; struct std { int roll; char sname[20]; struct dob d1; }; int main() …

Structure type Array

Preview

Length: 0 minutes

Structure type Array Structure type array can be created just like array of basic data types is created. Example: struct emp e[20]; In this example, array with name e of structure emp has been declared with size 20. Program of structure type array. #include<string.h> #include<stdio.h> struct emp { int empid; char ename[20]; }; int main() …

Structure type arguments in C

Preview

Length: 0 minutes

Structure type arguments in C  Structure type variables can be passed as arguments to functions. . In this case structure variable is passed as an actual argument to a function Program to demonstrate passing structure type variable as argument . #include<stdio.h> struct demo { int x,y; }; void disp(struct demo d1) { ++d1.x; – -d1.y;printf(“\nd1.x=%d”,d1.x); …

Function returning structure in C

Preview

Length: 0 minutes

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 Syntax to declare structure type pointer variable is: struct Struct_name  *var; var represents pointer variable of structure. We can use pointer variable of structure to access its elements pointer in two ways: (->) arrow operator (.) dot operator Program to demonstrate use of pointer variable of a structure. #include<stdio.h> struct …

Self Referential Structure

Preview

Length: 0 minutes

Self Referential Structure Self referential structure contains a pointer variable of itself . it is mainly used for implementing data structures like stack, queue, linked list, trees and graphs in C. Example struct NODE { float data; struct NODE  *link; }; int main() { struct NODE *START = NULL ;  struct NODE *N ;   N …

Introduction to Union in C Language

Preview

Length: 0 minutes

Introduction to Union in C Language It looks same as structure but implementation is different. Difference between structure and union is that the members of structure get different memory locations but members of a union share common memory location. C Language Compiler allocates memory to hold that element of union which has the largest size. …

Data File Handling in C

Preview

Length: 0 minutes

Data File Handling in C Data File handling is the way to store data permanently on computer. There are two ways of storing data in files: 1. Text Format In this case data is stored in form of ASCII characters. Data is stored in files with every line ended  by new line character. Human beings …

Steps to create a data file in C

Preview

Length: 0 minutes

Steps to create a data file in C 1. Declaration of file pointer variable File pointer is pointer variable of predefined structure FILE. When we need to store some data in a file, we have to specify the name of data file by using its file pointer variable. We can declare a file pointer variable …

File Input output in C

Preview

Length: 0 minutes

File Input output in C Different predefined functions of C language for file input/output are: 1.  fputc()/putc() function These functions are used to insert single character to a specified file. Syntax: fputc(C, Fpointer); OR putc(C, Fpointer);   C refers to character variable or constant whose value should be stored into a file. Fpointer  is the …

Random Access of Files in C

Preview

Length: 0 minutes

Random Access There are two predefined functions  in C language to provide random access in files: fseek() ftell() 1. fseek()  fseek() function can be  used to take file pointer to a particular position inside a  file. Syntax: fseek(Pointer, Position, Starting); Pointer is name of file pointer. Position is number of characters  to be jumped. Staring …

Command Line Arguments in C

Preview

Length: 0 minutes

Command Line Arguments in C We can provide values at command prompt using command line arguments. We have to specify the program name followed by values to be sent as arguments . Command line arguments to main() have two parameters passed as main ( int argc, char *argv[] ) argc specifies the number of arguments …

C program to find reverse of a number

Preview

Length: 0 minutes

C program to find reverse of a number #include<stdio.h> #include<conio.h> int main() { int m,n,r; printf(“\nEnter a number:=”); scanf(“%d”,&n); //123 r=0; while(n>0) { m=n%10; //3 2 1 r=r*10+m; //3 32 321 n=n/10; //12 1 0 } printf(“\nReverse=%d”,r); getch(); return  0; } Explanation /* n=123 r=0 m=3 r=3 n=12 m=2 r=32 n=1 m=1 r=321 n=0 */ …

C program to check whether a number is palindrome or not

Preview

Length: 0 minutes

C program to check whether a number is palindrome or not. #include<stdio.h> #include<conio.h> void main() { int m,n,r,t; printf(“\nEnter a number:=”); scanf(“%d”,&n); //n=1221 t=n; //t=1221 r=0; while(n>0) { m=n%10; r=r*10+m; n=n/10; } //r=1221 if(t==r) printf(“\nNumber is palendrome”); else printf(“\nNumber is not palendrome”); getch(); } Popular Books of Computer Science