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
What is Programming Language?
PreviewIntroduction to C Language
PreviewIntroduction 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
PreviewWhat 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
PreviewConstants 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
PreviewData 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
PreviewDisplay 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
PreviewRead 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
PreviewUnformatted 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
PreviewUnformatted 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
Preview4 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 …
Increment Decrement Operators in C Language | Increment operator in C Language | Decrement operators in C Language
PreviewIncrement Decrement Operators in C Language | Increment operator in C Language | Decrement operators in C Language 1. Increment Operator in C (++) Increment operator in C is used to add 1 to the existing value of a variable. It can be used in two ways:- Prefix Form of increment operator in C In …
Arithmetic Operators in C Language
PreviewArithmetic 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
PreviewRelational 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 …
Logical Operators in C Language | Logical AND in C Language | Logical Or in C Language| Logical NOT in C Language
PreviewLogical Operators in C Language | Logical AND in C Language | Logical Or in C Language| Logical NOT in C Language There are three logical operators. 1. Logical AND in C (&&) Logical AND (&&) is used to combine two relational expressions. If any input of this operator is 0, output will be 0. …
Bitwise operators in C | Bitwise Operator programs in C | Bitwise AND in C | Bitwise OR in C | Bitwise XOR in C | Bitwise complement in C | Bitwise left shift in C | Bitwise right shift in C
PreviewBitwise operators in C | Bitwise AND in C | Bitwise OR in C | Bitwise XOR in C | Bitwise complement in C | Bitwise left shift in C | Bitwise right shift in C Bitwise operators work with the binary form of numbers in C. There are six bitwise operators provided by C . …
Assignment Operators in C Language | Shorthand operators in C Language
PreviewAssignment 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
PreviewConditional 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 …
sizeof() operator in C Language | comma operator in C Language | Special operators in C Language
Previewsizeof() operator in C Language | comma operator in C Language | Special operators in C Language There are many special operators provided by C language which are as follows: sizeof() Comma 1. sizeof() operator in C Language This operator returns the size of a variable, constant or data type in terms of bytes. Program …
Implicit type Conversion in C Language | Automatic type conversion in C Language
PreviewImplicit 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
PreviewExplicit 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
PreviewPrecedence 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
PreviewControl 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
PreviewSimple 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
Previewif 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
PreviewNested 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
Previewif 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
Previewswitch 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
Previewfor 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++
Previewwhile 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
Previewwhile 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
Previewdo 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 …
Jumping statements in C Language | break statement in C Language | continue statement in C Language| goto statement in C Language| exit() in C Language
PreviewJumping statements in C Language | break statement in C Language | continue statement in C Language| goto statement in C Language| exit() in C Language There are four types of jumping statements in C language. 1. break statement in C Language break is a keyword of C language. break statement in C is used …
Introduction to characters in C Language | Character Variable in C Language | Character Variable Initialization in C Language:
PreviewIntroduction 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()
PreviewCharacter 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
PreviewStrings 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 …
String functions in C language with examples | strcpy, strcat, strcmp, strrev, strlen in C Language
PreviewString functions in C language with examples | strcpy, strcat, strcmp, strrev, strlen in C Language We need to include string.h header file in a program to use string functions. Different string functions in c language are: 1. strcpy() function in C Language strcpy() is one of the most popular String functions in c language . …
Array of strings in C language with examples | String array in C Language
PreviewArray 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
PreviewIntroduction 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 …
Two dimensional array in C Language | Initialization of Two dimensional array in C Language
PreviewTwo dimensional array in C Language | Initialization of Two dimensional array in C Language 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. …
Multi dimensional Array in C Language
PreviewMulti 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
PreviewIntroduction 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
PreviewTypes 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 Language | Call by value in C Language | Call by reference in C Language
PreviewArguments passing in C Language | Call by value in C Language | Call by reference in C Language 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 …
Recursion in C Language | Programs of recursion in C Language
PreviewRecursion 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() { …
Scope of variable in C Language | Local variable in C Language | Global variable in C Language
PreviewScope of variable in C Language | Local variable in C Language | Global variable in C Language Scope is the lifetime of variables. Variables have two types depending upon scope. Local variable Global variable a. Local variable in C Language Variable declared inside a function body is called local variable. It can exist only …
Storage class in C Language | auto , register, extern, static in C Language
PreviewStorage 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 …
Introduction to pointer in C | pointer operations in C | Operators associated with a pointer variable in C | Null pointer in C
PreviewIntroduction to pointer in C | pointer operations in C | Operators associated with a pointer variable in C | Null pointer in C It is the way to refer a memory location. A pointer variable can contain the address of another variable. Suppose we declare integer variable a as : int a=10; Variable a …
Pointer with Array in C Language | One dimensional array with Pointer in C Language | Two dimensional array with pointer in C Language
PreviewPointer 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
PreviewPointer 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
PreviewPointer 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
Previewvoid 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
PreviewPointer 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
PreviewDynamic 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 …
Introduction to Structure in C Language | Structure variable in C Language | Accessing structure members in C Language
PreviewIntroduction to Structure in C Language | Structure variable in C Language | Accessing structure members in C Language Structure is a user defined data of C language. It is a collection of different values of same or different data types. It is basically used to group logically related data. In C language, syntax for …
Nesting of Structure in C Language | Program of nesting of structure in C Language
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
PreviewDeclaring 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
PreviewPassing 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
PreviewFunction 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
PreviewStructure 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
PreviewSelf 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
PreviewIntroduction 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
PreviewData 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
PreviewSteps 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
PreviewFile 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 …
File Input in C Language | Read data from file in C Language | fgetc(), getc(), getw(), fgets(), fscanf() function in C language
PreviewFile Input in C Language | Read data from file in C Language | fgetc(), getc(), getw(), fgets(), fscanf() function in C language Different predefined functions of C language for file input are: 1. fgetc()/getc() function This function is used to read single character from a file. Syntax: v=fgetc( Fpointer); OR v=getc( Fpointer); v is …
Random Access of Files in C Language | fseek() function in C Language | ftell() function in C Language
PreviewRandom Access of Files in C Language | fseek() function in C Language | ftell() function in C Language 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, …
Command Line Arguments in C Language
PreviewCommand 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
PreviewC 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
PreviewC 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; }