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 Language – printf() function in C Language

Preview

Length: 0 minutes

Display output in C Language – 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 …

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 …

Unformatted Output Functions in C Language

Preview

Length: 0 minutes

Unformatted Output Functions in C Language 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 …

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 Language

Preview

Length: 0 minutes

4 Types of Operators in C Language Operator 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 …

Arithmetic Operators in C Language

Preview

Length: 0 minutes

Arithmetic Operators in C Language 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. – …

Relational Operators in C Language | Comparison operators in C Language

Preview

Length: 0 minutes

Relational Operators in C Language | Comparison operators in C Language 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 …

Assignment Operators in C Language | Shorthand operators in C Language

Preview

Length: 0 minutes

Assignment Operators in C Language | Shorthand operators in C Language 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 …

Conditional operator in C Language | Ternary Operator in C Language

Preview

Length: 0 minutes

Conditional operator in C Language | Ternary Operator in C Language 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 …

Implicit type Conversion in C Language | Automatic type conversion in C Language

Preview

Length: 0 minutes

Implicit type Conversion in C Language | Automatic type conversion in C Language 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 …

Explicit type conversion in C Language | Casting in C Language

Preview

Length: 0 minutes

Explicit type conversion in C Language | Casting in C Language 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 …

Precedence and Associativity of Operators in C Language | Expressions in C Language

Preview

Length: 0 minutes

Precedence and Associativity of Operators in C Language | Expressions in C Language 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 …

Control Structures in C Language | Control statements in C Language | Selection statements in C Language | Types of Looping in C Language

Preview

Length: 0 minutes

Control Structures in C Language | Control statements in C Language | Selection statements in C Language | Types of Looping in C Language Control structure can be used to alter the normal flow of a program depending upon some Condition. Control structures can be categorized into three types: Selection Statements Iterative/Looping Statements Jumping Statements …

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 Language

Preview

Length: 0 minutes

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

switch statement in C Language | Working of switch statement in C Language

Preview

Length: 0 minutes

switch statement in C Language | Working of switch statement in C Language 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 …

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

Preview

Length: 0 minutes

for statement in C language | Nesting of for in C language | for loop in C Language 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 . …

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 Language | do while loop in C Language

Preview

Length: 0 minutes

do while statement in C Language | do while loop in C Language 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 …

Introduction to characters in C Language | Character Variable in C Language | Character Variable Initialization in C Language:

Preview

Length: 0 minutes

Introduction to characters in C Language 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 in C Language …

Character functions in C Language | isalpha(), isdigit(), isalnum(), ispunct(), isspace(), isupper(), islower(), toupper(), tolower()

Preview

Length: 0 minutes

Character functions in C Language | isalpha(), isdigit(), isalnum(), ispunct(), isspace(), isupper(), islower(), toupper(), tolower() Character functions need ctype.h  header file to be included in the pgoram. Different character functions provided by C Language are: – isalpha() – isdigit() – isalnum() – ispunct() – isspace() – isupper() – islower() – toupper() – tolower() 1 isalpha() …

Strings in C language with examples | Reading and displaying a string variable in C Language | Initialization of a string variable in C Language

Preview

Length: 0 minutes

Strings in C language with examples | Reading and displaying a string variable in C Language | Initialization of a string variable in C Language String is group of one or more characters within double quotes (“). Example:  “Lovejot” , “2019” , “Rs4000”,  “[email protected]”  1. What is a String variable in C ? An array …

Array of strings in C language with examples | String array in C Language

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 Language | One dimensional array in C Language

Preview

Length: 0 minutes

Introduction to Array in C Language | One dimensional 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 …

Multi dimensional Array in C Language

Preview

Length: 0 minutes

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

Length: 0 minutes

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

Length: 0 minutes

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 …

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() { …

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 Array in C Language | One dimensional array with Pointer in C Language | Two dimensional array with pointer in C Language

Preview

Length: 0 minutes

Pointer with Array in C Language | One dimensional array with Pointer in C Language | Two dimensional array with pointer in C Language Pointers are associated closely with arrays because arrays are implemented internally in the form of pointers. One dimensional array with Pointer in C Language Suppose we have a one dimensional array …

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 Language | Pointer to function in C Language

Preview

Length: 0 minutes

Pointer with function in C Language | Pointer to function in C Language 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 …

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

Preview

Length: 0 minutes

void type pointer in C Language | using void pointer in C Language In C language we can’t declare a void type normal variable but we can declare a void type pointer variable. void type pointer variable can contain address of variable of any other data type. Program of void pointer in C Language #include<stdio.h> …

Pointer to pointer in C Language

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 Language | malloc() function in C Language | free() function in C Language

Preview

Length: 0 minutes

Dynamic memory allocation in C Language | malloc() function in C Language | free() function in C Language 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 …

Nesting of Structure in C Language | Program of nesting of structure in C Language

Length: 0 minutes

Nesting of Structure in C Language | Program of nesting of structure in C Language Defining one structure within another structure. is known as  nesting of structure. We can do it as follows: Program of nesting of structure in C Language #include<string.h> #include<stdio.h> struct dob {   int dd;   int mm;   int yy; …

Declaring Structure type Array in C Language

Preview

Length: 0 minutes

Declaring Structure type Array in C Language Structure type array can be created just like array of basic data types is created. Syntax: struct <struct_name><Arr_Name>[Size]; Here, struct is the keyword which specifies that a structure type variable is being initialized. struct_name referes to the name of structure of which we are going to create a …

Passing structure type arguments in C Language

Preview

Length: 0 minutes

Passing structure type arguments in C Language 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) {   …

Function returning structure type data in C Language

Preview

Length: 0 minutes

Function returning structure type data in C Language 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 …

Structure with Pointers in C Language | Declaring pointer variable of Structure in C Language

Preview

Length: 0 minutes

Structure with Pointers in C Language | Declaring pointer variable of Structure in C Language We can declare pointer variables of a structure just like other variables. We can declare structure type pointer variable and store address of  another structure variable in it. Syntax : Struct_name  *Struct_pointer; Here, Struct_name refers to the name of structure …

Self Referential Structure in C Language

Preview

Length: 0 minutes

Self Referential Structure in C Language 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 …

Introduction to Union in C Language | Declaring Union variable in C Language

Preview

Length: 0 minutes

Introduction to Union in C Language | Declaring Union variable 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 …

Data File Handling in C Language

Preview

Length: 0 minutes

Data File Handling in C Language 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 …

Steps to create a data file in C Language

Preview

Length: 0 minutes

Steps to create a data file in C Language 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 …

File Output in C Language | Write data into file in C Language | fputc(), putc(), putw(), fputs(), fprintf() function in C language

Preview

Length: 0 minutes

File Output in C Language | Write data into file in C Language | fputc(), putc(), putw(), fputs(), fprintf() function in C language 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 …

Command Line Arguments in C Language

Preview

Length: 0 minutes

Command Line Arguments in C Language 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 …

C program to find reverse of a number

Preview

Length: 0 minutes

C program to find reverse of a number #include<stdio.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); 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> int 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”); return 0; }