Free · 99 Topics · No Signup
C Notes
Core C — syntax, pointers, memory, structures and systems programming — written by CodingNow 2.0's mentors. Free to read, structured to actually help you learn.
C notes by CodingNow 2.0 cover 99 topics — from c home to c projects — each explained with short definitions, syntax and runnable code examples. They are 100% free, need no signup, and work as quick revision for college exams, C interviews and CodingNow 2.0's mentor-led C course in Pitampura, Delhi.
No notes found. Try a different search term, or browse all C notes.
C Tutorial
60 of 60 topics publishedC HOME
C is a general-purpose programming language that has been widely used for over 50 years.
C Intro
C is a general-purpose programming language created by Dennis Ritchie at Bell Labs in 1972.
C Get Started
At W3Schools, you can start learning C without installing anything.
C Syntax
You have already seen the following code a couple of times in the first chapters. Let's break it down and understand what each part does:
Statements
A computer program is a list of instructions that a computer follows.
C Output
To output values or print text in C, you can use the printf() function:
New Lines
To start a new line when printing text, you can use the \n character:
C Comments
Comments are notes for humans. They help explain code and make it easier to read.
C Variables
Variables are containers for storing data values, like numbers and characters.
Format Specifiers
Format specifiers are used together with the printf() function to print variables.
Change Values
If you assign a new value to an existing variable, the new value will replace the old one:
Multiple Variables
To declare more than one variable of the same type, use a comma-separated list:
Variable Names
All C variables must be identified with unique names.
Real-Life Examples
Often in our examples, we simplify variable names to match their data type (myInt or myNum for int types, myChar for char types, and so on). This is done to
C Data Types
As explained in the Variables chapter, a variable in C must be a specified data type, and you must use a format specifier inside the printf() function to disp
Characters
The char data type is used to store a single character.
Numbers
Use int when you need to store a whole number without decimals, like 35 or 1000, and float or double when you need a floating point number (with decimals)
Decimal Precision
You have probably already noticed that if you print a floating point number, the output will show many digits after the decimal point:
Memory Size
We introduced in the data types chapter that the memory size of a variable varies depending on the type:
Real-Life Example
Here's a real-life example of using different data types, to calculate and output the total cost of a number of items:
Extended Types
Besides the basic types ( int , float , double , char ), C also gives you extended keywords ( short , long , unsigned ) to control how large the number is,
C Type Conversion
Sometimes, you have to convert the value of one data type to another type. This is known as type conversion.
C Constants
Now that you have seen different types of variables in C, you should also know that sometimes you need variables that should not change.
C Operators
Operators are used to perform operations on variables and values.
Arithmetic
Arithmetic operators are used to perform common mathematical operations.
Assignment
Assignment operators are used to assign values to variables.
Comparison
Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions.
Logical
As with comparison operators, you can also test for true or false values with logical operators.
Precedence
When a calculation contains more than one operator, C follows order of operations rules to decide which part to calculate first.
C Booleans
Very often, in programming, you will need a data type that can only have one of two values, like:
Real-Life Examples
Let's use booleans in a real-life example where we want to find out if a person is old enough to vote.
C If...Else
You already know that C supports familiar comparison conditions from mathematics, such as:
else
Use the else statement to specify a block of code to be executed if the condition is false .
else if
Use the else if statement to specify a new condition to test if the first condition is false .
Short Hand If
There is also a short-hand if...else , known as the ternary operator because it uses three operands.
Nested If
You can also place an if statement inside another if . This is called a nested if statement.
Logical Operators
You can combine or reverse conditions using logical operators. These work together with if , else , and else if to build more complex decisions.
Real-Life Examples
This example shows how you can use if..else to "open a door" if the user enters the correct code:
C Switch
Instead of writing many if..else statements, you can use the switch statement.
C While Loop
Loops can execute a block of code as long as a specified condition is true.
Do/While Loop
The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat
Real-Life Examples
To demonstrate a practical example of the while loop, we have created a simple "countdown" program:
C For Loop
When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop:
Nested Loops
It is also possible to place a loop inside another loop. This is called a nested loop.
Real-Life Examples
To demonstrate a practical example of the for loop, let's create a program that counts to 100 by tens:
C Break/Continue
You have already seen the break statement used in an earlier chapter of this tutorial. It was used to "jump out" of a switch statement.
C Arrays
Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.
Array Size
To get the size of an array, you can use the sizeof operator:
Array Loops
You can use a for loop to go through the elements of an array by writing the size of the array in the loop condition (in this example the array has 4 elements
Real-Life Examples
To demonstrate a practical example of using arrays, let's create a program that calculates the average of different ages:
Multidimensional Arrays
In the previous chapter, you learned about arrays, which is also known as single dimension arrays. These are great, and something you will use a lot while progr
C Strings
Strings are used for storing text/characters.
Special Characters
Because strings must be written within quotes, C will misunderstand this string, and generate an error:
String Functions
C also has many useful string functions, which can be used to perform certain operations on strings.
C User Input
You have already learned that printf() is used to output values in C.
C Memory Address
When a variable is created in C, a memory address is assigned to the variable.
C Pointers
You learned from the previous chapter, that we can get the memory address of a variable with the reference operator & :
Pointers & Arrays
You can also use pointers to access arrays.
Pointer Arithmetic
Pointer arithmetic means changing the value of a pointer to make it point to a different element in memory.
Pointer to Pointer
You can also have a pointer that points to another pointer. This is called a pointer to pointer (or "double pointer").
C Functions
9 of 9 topics publishedC Functions
A function is a block of code which only runs when it is called.
C Function Parameters
Information can be passed to functions as a parameter. Parameters act as variables inside the function.
C Scope
Now that you understand how functions work, it is important to learn how variables act inside and outside of functions.
C Function Declaration
You have already learned from the previous chapters that you can create and call a function in the following way:
C Math Functions
There is also a list of math functions available, that allows you to perform mathematical tasks on numbers.
C Inline Functions
You might sometimes see the inline keyword used in other people's functions. It's not something you need to use often as a beginner, but it's good to know wha
C Recursion
Recursion is the technique of making a function call itself. This technique provides a way to break complicated problems down into simple problems which are eas
C Function Pointers
A function pointer is like a normal pointer, but instead of pointing to a variable, it points to a function.
Callback Functions
A callback function is a function that is passed as an argument to another function.
C Files
3 of 3 topics publishedC Create Files
In C, you can create, open, read, and write to files by declaring a pointer of type FILE , and use the fopen() function:
C Write To Files
Let's use the w mode from the previous chapter again, and write something to the file we just created.
C Read Files
In the previous chapter, we wrote to a file using w and a modes inside the fopen() function.
C Structures
6 of 6 topics publishedC Structures
Structures (also called structs) are a way to group several related variables into one place.
C Nested Structures
A structure can also contain another structure as a member. This is called a nested structure, and it is useful when you want to group related data together in
C Structs & Pointers
You can use pointers with structs to make your code more efficient, especially when passing structs to functions or changing their values.
C Unions
A union is similar to a struct in that it can store members of different data types.
C typedef
The typedef keyword lets you create a new name (an alias) for an existing type. This can make complex declarations easier to read, and your code easier to mai
C Struct Padding
When you create a struct in C, the compiler may add some extra bytes of padding between members.
C Enums
1 of 1 topics publishedC Memory
7 of 7 topics publishedC Memory Management
Memory management is the process of handling how much memory a program uses through different operations.
C Allocate Memory
The process of reserving memory is called allocation. The way to allocate memory depends on the type of memory.
C Access Memory
Dynamic memory behaves like an array, with its data type specified by the type of the pointer.
C Reallocate Memory
If the amount of memory you reserved is not enough, you can reallocate it to make it larger.
C Deallocate Memory
When you no longer need a block of memory you should deallocate it. Deallocation is also referred to as "freeing" the memory.
C Structs and Memory
You can also use dynamic memory with structures.
C Memory Example
To demonstrate a practical example of dynamic memory, we created a program that can make a list of any length.
C Errors
5 of 5 topics publishedC Errors
Even experienced C developers make mistakes. The key is learning how to spot and fix them!
C Debugging
Debugging is the process of finding and fixing errors (bugs) in your program.
C NULL
NULL is a special value that represents a "null pointer" - a pointer that does not point to anything.
C Error Handling
Error handling lets you detect and respond to problems in your program, like a file that can't be opened or memory that can't be allocated, so your program does
C Input Validation
When users enter data into a C program, they might type something unexpected. Input validation makes sure the input is correct before the program continues.
C More
7 of 7 topics publishedC Date
In C, you can use the <time.h header to work with dates and times.
C Random Numbers
In C, you can make random numbers with the rand() function, which is found in the <stdlib.h library.
C Macros
In C, the preprocessor runs before the actual compilation begins. It handles things like including files and defining macros.
C Organize Code
In C programming, modular programming means splitting your code into smaller, reusable parts.
C Storage Classes
Storage classes define the lifetime, visibility, and memory location of variables.
C Bitwise Operators
Note: This is a more advanced topic in C. If you are new to programming, don't worry if it feels tricky at first - bitwise operators are mainly used in special
C Fixed-width Integers
In C, the size of int , short , and long types can vary depending on your computer and system. For example, an int might take up 2 bytes on one system, an
C Projects
1 of 1 topics publishedReady to go from notes to a real career?
Join CodingNow 2.0's C course — live mentorship, hands-on projects, and 100% placement support in Delhi NCR.
Enroll Now — Free Demo AvailableC Notes – FAQs
What students search before reading C notes.