C Tutorial

C Tutorials

Our 1000 C Tutorial covers all C Language topics either in Tutorial Format or a Question Format. Each tutorial contains the description along with C Programming Example (with Code). These C tutorials are suitable for all types of users (beginners, intermediate or advanced users).

1. Tutorial on C Concepts & Statements

An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal. Conditional Operator returns the statement depends upon the given expression result. The run-time stack is a stack of activation records. Activation records keep track of the local variables. Storage Classes are used to describe about the features of a function. Linkage of any variable and/or function defines the Area of the Program in which they are accessible. A scope is a region of the program, and the scope of variables refers to the area of the program where the variables can be accessed after its declaration. The following section gives a collection of C Tutorials which are categorized into various Categories like Programs on Escape Sequences, Run-time Stack, Conditional Statements with Examples, While, For and Do-While Loops Statements, Storage Classes, Linkage & Scope of Variables.

Escape Sequences in C
Differences between ANSI C and K&R C
Difference between Declaration and Definition of a Variable in C
Compilation Stages of C Programming
Difference between Macros and Constants in C
Runtime Stack in C with Examples
Conditional Statements in C Programming
What Happens if the Conditional Expression is Missing in an if Statement?
What is Dangling else in C?
For, While and Do-While Loop Statements in C
Difference between For and While Loop in C
Difference between While and Do-while Loop in C
goto Statement in C
Storage Classes in C Language with Examples
Does a Function have any Storage Class in C Language?
Linkage, Scope of Variables and Functions in C

2. Tutorial on C Operators and Expressions

C programming has various operators to perform tasks including arithmetic, relational, conditional, logical and bitwise operations. Relational operators are used for comparison of the values of two operands. Logical Operators are used to combine two or more conditions. Bitwise operators is used to perform bit-level operations on the operands. Assignment operators are used to assign value to a variable. Cast is a special operator that forces one data type to be converted into another. Unary operators that act upon a single operand to produce a new value. sizeof operator is used to calculate the size of data type or variables. This section contains C programs on Operators like arithmetic, relational, conditional, logical and bitwise operations, sizeof Operator, Unary Operators and Cast Operator.

What is C Expression?
Difference between Expression and Statement in C
Operators in C Language
Operator Precedence and Associativity in C
Assignment Operators in C with Examples
Arithmetic Operators in C
Logical and Arithmetic Shifts in C with Examples
Bitwise Operators in C with Examples
Relational Operators in C with Examples
Logical Operators in C with Examples
Increment and Decrement Operators in C with Examples
Conditional Operator in C with Examples
Comma Operator in C with Examples
Boolean Values in C
What does sizeof Operator Return in C?
Is sizeof Operator in C Evaluate the Expression for Determining its Size
Cast Operator in C
Unary Operator in C
L Value and R Value in C Language with Examples
How can One Determine Whether a Right Shift of a Signed Value is Performed as an Arithmetic or a Logical Shift

advertisement
advertisement

3. C Pointers Tutorial

Pointer is a variable which contains the address in memory of another variable. The rules for assigning one pointer to another are tighter than the rules for numeric types. NULL Pointer is a pointer which is pointing to nothing. When a pointer holds the address of another pointer then such type of pointer is known as pointer-to-pointer or double pointer. Lvalue refers to some location or storage used by some data object. This section contains C programs on Pointers, Operators addressof, Pointers with Modular Programming, Pointer Compatibility, Pointer Expressions, NULL Pointer and Double Pointer.

What is the Word Datatype in C?
Difference between Pointer and Ordinary Variable in C
Can Datatype of a Value be determined by Examining its Bits in C?
Does Declaring a Pointer Allocate Memory in C?
What is the use of addressof (&) and asterisk (*) with Respect to Pointers in C?
What are the Benefits of using C Pointers in Modular Programming?
What is Pointer Indirection or Dereferencing in C?
What is an Uninitialized or Illegal Pointer in C?
Pointer Constants in C with Examples
What is Pointer Compatibility in C Programming?
Difference between Pointers, const type * pname, type * const pname, and const type * const pname in C
Difference between Expression and Statement in C
Addressof Operator and Register Variable in C
NULL Pointer in C with Examples
NULL Pointer Indirection in C with Examples
Which Pointer Expressions in C Programming are referred to as L-Values?
Pointer Arithmetic in C with Examples
Double Pointer (Pointer to Pointer) in C with Example

4. C Functions Tutorial

Parameters which are passed in the function call are known as actual parameters or actual arguments. Parameters which are received by the called function are known as formal parameters or formal arguments. Function is a block of statements, which is used to perform a specific task. Process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive function. The following section contains C programs on functions, integral components, actual and formal arguments, ADTs and black boxes Context, recursion and iterator.

Can the Parameters of a Function in C be Declared Static?
Which Function Comes as an Integral Component of C Program?
Functions in C with Examples
Function Arguments in C Programming with Examples
Actual and Formal Arguments in C
Can a Function have a Variable Number of Arguments in C?
ADTs and Black Boxes Functions in C
Explain Recursion with Example in C
Difference Between Recursion and Iteration in C
Efficiency of Recursion vs Iteration in C

5. C Tutorial on Arrays

An array is collection of items stored at continuous memory locations. One Dimensional Arrays is a fixed sequenced collection of elements of the same data type. Subscript operator, ‘[]’, which aside from having higher precedence than indirection operator (*) is same as indirection operator. So, subscripts in arrays perform indirection or dereferencing. An array with more than one dimension is called a multidimensional array. strlen() function primarily a string handling function used with strings and always returns actual no. of characters in the string without counting on NULL byte. This section contains C Programs on Arrays, one-dimensional array, array subscripts, pointers, functions, strlen() function and multidimensional arrays.

Difference between Array and Variable in C
One Dimensional Array in C with Examples
Array Subscripts in C with Examples
Can we Use a Pointer for Subscript to Access an Array in C?
Are Pointer References More Efficient than Array Indexes in C
Difference between array[i] and i[array] Expressions
Array in C with Examples
Difference between Pointer and Array in C
How to Pass a 1D Array as a Function Arguments in C?
Static and Automatic Initialization of an Array in C
What is Incomplete Initialization in C Programming?
Character Array Initialization in C
Multidimensional Array in C Programming
How does C Allocate Memory of Data Elements in a Multidimensional Array?
Pointer to an Array in C
How to Pass a 2D Array as a Function Arguments in C?
Array of Pointers in C with Examples
Size of an Array using sizeof Operator OR strlen() Function in C

advertisement

6. Characters & Strings Tutorial

Character constants are used to represent characters in the execution character set. Char values are stored in 1 byte, and are encoded as numbers using the ASCII encoding. Strings are actually one-dimensional array of characters terminated by a null character. Strings in C comprise of individual parts separated by one or more characters called delimiters. These individual parts are called tokens. In order to process these individual parts, they have to be extracted from the string. strtok() isolates these parts, discards the delimiters and NULL terminate them. Command line argument is a parameter supplied to the program when it is invoked. The following section contains C programs on type size_t, null characters, strings, strtok() function, libc functions, memory functions and command-line arguments.

What is size_t in C?
NULL Character in C with Examples
Difference between Character and String in C
Difference between Character Array and String in C
Difference between strlen() and sizeof() for String in C
Restricted vs Unrestricted String Function in C
Difference between Basic and Advanced String Searching in C
strtok() Function in C with Examples
How are Errors Reported in a C Program When Operating System Fails to Perform some Requested Job
Explain Library Functions that Operate on Characters with Examples
Memory Allocation Functions in C
Command Line Arguments in C with Examples

7. Structures & Unions Tutorial

Structure is a user defined data type. Structure is the collection of variables of different types under a single name for better handling. Union is a data type that allows to store different data types in the same memory location. Two structures, for example, say A and B, are called mutually dependent if one of members of each refers to other structure. Self Referential Structure is the Data Structure in which the pointer refers to the structure of the same type. Structure written inside another structure is called as Nested structure. Bit fields are declared as other structure declarations with difference that member’s are fields of one or more bits. This section contains programs on structures like self referential structure, mutually dependent and nested structures, bit fields and union.

advertisement
Difference between Structure and Array in C
Difference between Structure Pattern, Template and Variable in C
How to Access Members of a Structure in C?
Self Referential Structure in C
Mutually Dependent Structures in C
Structure in C Programming with Examples
Difference between Pointer Arithmetic on Structures and Pointer Arithmetic on Arrays in C
Nested Structure in C with Examples
Difference between Dot and Arrow Operators in C
Structure Boundary Alignment in C
How to Pass or Return a Structure from a Function in C
Bit Fields in C Programming with Examples
What is Union in C Language?
Difference between Structure and Union in C

8. C Tutorials on Dynamic Memory Allocations

The process of allocating memory at runtime is known as dynamic memory allocation. Free Store is a pool of un-allocated heap memory given to a program that is used by the program for dynamic allocation during the execution of program. malloc() function is used to allocate space in memory during the execution of the program. calloc() function is used to allocate storage to a variable while the program is running. realloc() function is used to resize allocated memory without losing old data. The following section contains C Programs on compile time and runtime memory allocation, pool of free memory, malloc(), calloc(), realloc(), free() and memory leak.

Difference between Compile Time and Run Time Memory Allocation in C
What is Free Pool of Memory in C?
Dynamic Memory Allocation in C with Examples
Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc() Functions
Common Errors During Dynamic Memory Allocation in C
What is Memory Leak in C?
Where is Memory Allocated During Dynamic Memory Allocation in C Programming

9. Structures & Pointers Tutorial

Linked list is an ordered set of data elements, each containing a link to its successor. A linked list that can only be traversed in forward direction is called a singly linked list. A singly linked list is traversed from beginning through till end using the root pointer. root contains the address of start of list. Singly linked list in which values are inserted in either ascending or descending order is called an ordered singly linked list. In unordered list we shall insert new value at the end of the list. A singly liked list can be traversed in one and in Forward Direction only while doubly linked list in either Forward or Backward direction. The following section contains C programs on linked list, singly liked list, doubly linked list, ordered and unordered singly linked lists.

Linked List in C with Examples
What is Dynamic and Static Memory Allocation in C?
Singly Linked List in C Programming
Ordered and Unordered Singly Linked Lists in C
Singly Linked List Operations in C
What is a Doubly Linked List in C?
Doubly Linked List Operations in C

10. Tutorial on Advanced Pointers

A pointer is a variable that holds address, address of a variable of any basic types, address of a structure, address of an array or address of some other pointer variable. Function pointer can be passed as an argument and can also be returned from a function. Function calls back user’s function is called callback function. jump table is a method of transferring program control to another part of a program using a table of branch or jump instructions. A string literal is a sequence of characters terminated by null byte ‘0’. This section contains C programs on pointer to pointer, pointer to function, callback functions, jump tables, command line arguments and string literal operations.

Pointer to Pointer in C with Example
What is Declaration by Inference in C?
What is Function Pointer in C?
What are Callback Functions in C?
What are Jump Tables in C?
How Command Line Arguments are Passed and Processed in C?
String Literals Operations using Pointers in C

11. C Pre-Processor Tutorial

Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. #define is a C preprocessor directive used to define macros. Macros is a process where an identifier in a program is replaced by a predefined string or value. File inclusion makes it easy to handle collections of #defines and declarations. The null directive is a line with a pound sign but contains nothing else. These directives are simply deleted by the preprocessor. “##” construct can be used in the replacement text of function like macro or object like macro. This macro combines two tokens on either side of it into a single token called an identifier. This section contains C programs on preprocessor & its directives, #define directive, macros, file inclusion and nested file inclusion.

Difference between Preprocessor and Compiler
How to Compile C Program in Linux?
What is C Preprocessor?
What are Preprocessor Directives in C?
What is #define Directive in C Program?
Macros in C with Examples
Difference between Macros and Functions in C
What is #undef Directive in C Programs?
#if, #elif and #else Directives in C
Command Line Macro Definitions in C
Conditional Compilation in C
What is Nested Directive in C?
Why we use #include Directive in C Program
What is File Inclusion in C
What is Nested File Inclusion in C Programming
#error, #pragma and #null Directives in C
What is ## preprocessor Directive in C?

12. C Tutorial on File I/O Handling

ANSI C implementations include library in specification. Standard dictates a mandated set of functions, which have required interface and they operate in prescribed manner. perror() displays a message on stderr describing the most recent error that occurred during a library function call or system call. Text streams may have certain characteristics that may vary from system to system. fopen() function is used to open a given file and associates a stream with the file. ungetc() returns previously read character back to the stream so that it could be read again. clearerr function clears the error and end-of-file indicators for the stream pointed to by stream. The following section contains C programs on ansi c implementation, perror() and exit() function, text and binary streams, binary i/o, stream error and manipulation functions.

What is Portability in C Programming?
What is ANSI C Implementation?
perror() Function in C with Example
exit() Function in C with Example Program
Difference between Standard I/O Library and ANSI in C
What is Stream in C Programming?
Text and Binary Streams in C
EOF, FOPEN_MAX and FILENAME_MAX Constants in C
Difference between I/O on Standard Streams and Files in C
Explain the Type of I/O Operations Supported by the C Library
Opening and Closing of File Streams in C
Difference between Macros and Functions in C
What is the ungetc() Function in C?
Formatted and Unformatted Input/Output Functions in C
What is Binary File I/O in C?
Flushing and Seeking Functions in C
Which Functions in C can we Use to Modify Buffering?
What are Stream Error Functions in C Language?
Temporary Files in C – tmpfile() and tmpnam()
File Manipulation Functions in C
File Handling Functions in C

13. Tutorial on Standard C Library

C Standard Library is a set of C built-in functions, constants and header files. Signals are mechanisms for communicating with and manipulating processes. A function that handles signals is called a signal handler. abort() function terminates execution of a program abnormally. It’s defined in ‘stdlib.h’ header. assert() is a macro therefore it doesn’t have a prototype. system() function is used to execute shell commands which we can’t use directly in c programs. qsort() function is used to sort an array of values in ascending order. bsearch() function is used to locate a given value in a sorted array using binary search mechanism. This section contains C programs on standard library functions, pseudo random numbers, signal handlers, getenv() and abort() functions, locale, qsort() and bsearch() functions.

What is Standard Library in C?
Random and Pseudo Random Numbers in C
String Conversion Functions in C
Floating Point Functions in C Standard Library
Trigonometric Functions in Standard C Library
Hyperbolic Functions in C Standard Library
Logarithmic and Exponential Functions in C Library
What is Power Function in C Library?
Ceil, Floor, Absolute Value and Remainder Functions in C
Date and Time Functions in C
clock() Function in C
What is Time of Day Function in C Library?
Date and Time Conversion Functions in C
setjmp() and longjmp() Functions in C Library
Are the Signals Asynchronous or Synchronous?
Signal Handling in C
How are Signals Processed?
Signal Handlers in C
What is Importance of Volatile Data in Context with Signals
abort() Function in C with Example
Integer Functions in Standard C Library
Which String Conversion Functions in Standard C Library Return Type “double” Values
Where is “assert” Macro Primarily Used in a C Program
getenv() Function in C
What is System() Function in C?
qsort() and bsearch() Functions in C
What is Locale in C?

14. Tutorial on C Runtime Environment

The runtime environment implements the execution model, built-in functions, and other fundamental behaviors of a programming language. Function prologue is part of function does all work needed to start up the function. It begins by reserving space for local variables and other values on the runtime stack. Function epilogue cleans up the stack frame just before function is done and returns to the caller. Stack frame is the area on stack which function uses to store local variables and other values. The following section contains C programs on runtime environment limits, function prologue and epilogue, stack frame, function prototypes, frame and stack pointers.

How do I Run an Assembly Language Program in Linux?
What are the Runtime Environment Limits in C?
Function Prologue and Epilogue in C
What is Stack Frame in C?
Do Local Variables and Function Prototypes in a C Program Produce any Assembly Code
Memory Layout of C Program
Is this True that all Variables Declared to be Registers in a C Program Allocated Necessarily in Register Memory
Which Variable Should be Declared as Registers in a C Program?
Difference between Frame Pointer and Stack Pointer
What is a Stack Frame, and How does it Work in the Context of a Function Call?
What Happens During Function Epilogue Phase?

Important C Links:

Advanced C Videos:

Wish you the best in your endeavor to learn and master C programming language!

advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.