Core C — syntax, pointers, memory, structures and systems programming — written by Aivasu Tech Institute's mentors. Free to read, structured to actually help you learn.
C notes by Aivasu Tech Institute 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 Aivasu Tech Institute's mentor-led C course in Pitampura, Delhi.
No notes found. Try a different search term, or browse all C notes.
C is a general-purpose programming language that has been widely used for over 50 years.
C is a general-purpose programming language created by Dennis Ritchie at Bell Labs in 1972.
At W3Schools, you can start learning C without installing anything.
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:
A computer program is a list of instructions that a computer follows.
To output values or print text in C, you can use the printf() function:
To start a new line when printing text, you can use the \n character:
Comments are notes for humans. They help explain code and make it easier to read.
Variables are containers for storing data values, like numbers and characters.
Format specifiers are used together with the printf() function to print variables.
If you assign a new value to an existing variable, the new value will replace the old one:
To declare more than one variable of the same type, use a comma-separated list:
All C variables must be identified with unique names.
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
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
The char data type is used to store a single character.
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)
You have probably already noticed that if you print a floating point number, the output will show many digits after the decimal point:
We introduced in the data types chapter that the memory size of a variable varies depending on the type:
Here's a real-life example of using different data types, to calculate and output the total cost of a number of items:
Besides the basic types ( int , float , double , char ), C also gives you extended keywords ( short , long , unsigned ) to control how large the number is,
Sometimes, you have to convert the value of one data type to another type. This is known as type conversion.
Now that you have seen different types of variables in C, you should also know that sometimes you need variables that should not change.
Operators are used to perform operations on variables and values.
Arithmetic operators are used to perform common mathematical operations.
Assignment operators are used to assign values to variables.
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.
As with comparison operators, you can also test for true or false values with logical operators.
When a calculation contains more than one operator, C follows order of operations rules to decide which part to calculate first.
Very often, in programming, you will need a data type that can only have one of two values, like:
Let's use booleans in a real-life example where we want to find out if a person is old enough to vote.
You already know that C supports familiar comparison conditions from mathematics, such as:
Use the else statement to specify a block of code to be executed if the condition is false .
Use the else if statement to specify a new condition to test if the first condition is false .
There is also a short-hand if...else , known as the ternary operator because it uses three operands.
You can also place an if statement inside another if . This is called a nested if statement.
You can combine or reverse conditions using logical operators. These work together with if , else , and else if to build more complex decisions.
This example shows how you can use if..else to "open a door" if the user enters the correct code:
Instead of writing many if..else statements, you can use the switch statement.
Loops can execute a block of code as long as a specified condition is true.
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
To demonstrate a practical example of the while loop, we have created a simple "countdown" program:
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:
It is also possible to place a loop inside another loop. This is called a nested loop.
To demonstrate a practical example of the for loop, let's create a program that counts to 100 by tens:
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.
Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.
To get the size of an array, you can use the sizeof operator:
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
To demonstrate a practical example of using arrays, let's create a program that calculates the average of different ages:
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
Strings are used for storing text/characters.
Because strings must be written within quotes, C will misunderstand this string, and generate an error:
C also has many useful string functions, which can be used to perform certain operations on strings.
You have already learned that printf() is used to output values in C.
When a variable is created in C, a memory address is assigned to the variable.
You learned from the previous chapter, that we can get the memory address of a variable with the reference operator & :
You can also use pointers to access arrays.
Pointer arithmetic means changing the value of a pointer to make it point to a different element in memory.
You can also have a pointer that points to another pointer. This is called a pointer to pointer (or "double pointer").
A function is a block of code which only runs when it is called.
Information can be passed to functions as a parameter. Parameters act as variables inside the function.
Now that you understand how functions work, it is important to learn how variables act inside and outside of functions.
You have already learned from the previous chapters that you can create and call a function in the following way:
There is also a list of math functions available, that allows you to perform mathematical tasks on numbers.
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
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
A function pointer is like a normal pointer, but instead of pointing to a variable, it points to a function.
A callback function is a function that is passed as an argument to another function.
In C, you can create, open, read, and write to files by declaring a pointer of type FILE , and use the fopen() function:
Let's use the w mode from the previous chapter again, and write something to the file we just created.
In the previous chapter, we wrote to a file using w and a modes inside the fopen() function.
Structures (also called structs) are a way to group several related variables into one place.
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
You can use pointers with structs to make your code more efficient, especially when passing structs to functions or changing their values.
A union is similar to a struct in that it can store members of different data types.
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
When you create a struct in C, the compiler may add some extra bytes of padding between members.
Memory management is the process of handling how much memory a program uses through different operations.
The process of reserving memory is called allocation. The way to allocate memory depends on the type of memory.
Dynamic memory behaves like an array, with its data type specified by the type of the pointer.
If the amount of memory you reserved is not enough, you can reallocate it to make it larger.
When you no longer need a block of memory you should deallocate it. Deallocation is also referred to as "freeing" the memory.
You can also use dynamic memory with structures.
To demonstrate a practical example of dynamic memory, we created a program that can make a list of any length.
Even experienced C developers make mistakes. The key is learning how to spot and fix them!
Debugging is the process of finding and fixing errors (bugs) in your program.
NULL is a special value that represents a "null pointer" - a pointer that does not point to anything.
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
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.
In C, you can use the <time.h header to work with dates and times.
In C, you can make random numbers with the rand() function, which is found in the <stdlib.h library.
In C, the preprocessor runs before the actual compilation begins. It handles things like including files and defining macros.
In C programming, modular programming means splitting your code into smaller, reusable parts.
Storage classes define the lifetime, visibility, and memory location of variables.
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
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
Join Aivasu Tech Institute's C course — live mentorship, hands-on projects, and 100% placement support in Delhi NCR.
Enroll Now — Free Demo Available✳ Common questions
What students search before reading C notes.