Congratulations! You have reached the final lesson of the C Programming course. This lesson provides a complete revision of important C concepts covered throughout the tutorial.
C is a general-purpose programming language widely used for system programming, embedded programming, and application development.
#include <stdio.h>
int main()
{
printf("Hello C");
return 0;
}
C was developed by Dennis Ritchie at Bell Labs in the early 1970s.
C became highly influential in systems programming and has influenced many later programming languages.
The main() function is the designated entry point of a hosted
C program.
int main()
{
return 0;
}
Program execution begins by calling main().
A variable is a named object used to store a value that can be changed during program execution.
int age = 20;
age = 21;
A constant represents a value that is not intended to be modified through the identifier during the program's execution.
const int DAYS = 7;
The const qualifier can be used to create an object that should
not be modified through that identifier.
A data type determines the kind of value an object can represent and influences its storage and operations.
int age;
float price;
char grade;
double distance;
An operator is a symbol that performs an operation on one or more operands.
int sum = a + b;
int result = a * b;
C provides arithmetic, relational, logical, assignment, bitwise, conditional, and other operators.
if(age >= 18)
{
printf("Adult");
}
The if statement executes a block when its controlling
expression evaluates to a nonzero value.
switch(choice)
{
case 1:
printf("One");
break;
case 2:
printf("Two");
break;
default:
printf("Other");
}
The switch statement selects among labeled cases based on the
value of its controlling expression.
for(int i = 1; i <= 5; i++)
{
printf("%d ", i);
}
A for loop is commonly used when initialization, a condition,
and an iteration expression are needed for repeated execution.
int i = 1;
while(i <= 5)
{
printf("%d ", i);
i++;
}
The condition of a while loop is tested before each iteration.
int i = 1;
do
{
printf("%d ", i);
i++;
}
while(i <= 5);
A do-while loop executes its body before testing its condition,
so the body executes at least once.
for(int i = 1; i <= 10; i++)
{
if(i == 5)
break;
printf("%d ", i);
}
The break statement terminates the nearest enclosing loop or
switch statement.
for(int i = 1; i <= 5; i++)
{
if(i == 3)
continue;
printf("%d ", i);
}
The continue statement skips the rest of the current loop
iteration and proceeds with the next iteration according to the loop.
int add(int a, int b)
{
return a + b;
}
A function is a named block of code that performs a particular operation and can be called from other parts of a program.
int factorial(int n)
{
if(n <= 1)
return 1;
return n * factorial(n - 1);
}
Recursion occurs when a function directly or indirectly calls itself. A recursive function needs an appropriate base case.
int numbers[5] = {10, 20, 30, 40, 50};
An array stores multiple elements of the same type in contiguous storage.
C array indexing starts at 0.
char name[] = "Rahul";
A C string is a sequence of characters terminated by a null character
'\0'.
String-related functions are commonly provided by
string.h.
int number = 10;
int *ptr = &number;
printf("%d", *ptr);
A pointer stores an address. The unary * operator can be used
to access the object referred to by a valid pointer.
struct Student
{
int id;
char name[50];
float marks;
};
A structure groups related members that may have different data types.
union Data
{
int number;
float price;
char letter;
};
Members of a union share the same storage. At a given time, the stored representation should be interpreted according to the member being used, subject to the C language rules.
typedef unsigned int uint;
uint age = 20;
The typedef keyword creates an alternative name for an
existing type.
int *numbers;
numbers = malloc(5 * sizeof(int));
if(numbers != NULL)
{
/* use memory */
free(numbers);
}
Dynamic memory can be allocated during program execution using functions
such as malloc(), calloc(), and
realloc(), and released with free().
FILE *file;
file = fopen("data.txt", "r");
if(file != NULL)
{
/* read file */
fclose(file);
}
File handling allows a C program to read from and write to files using
facilities provided by stdio.h.
#include <stdio.h>
Header files commonly contain declarations, macros, and type definitions that can be shared between source files.
Project headers are commonly included using:
#include "student.h"
FILE *file = fopen("data.txt", "r");
if(file == NULL)
{
perror("File error");
}
C programs commonly handle errors using return values, null-pointer checks,
errno, perror(), and appropriate validation.
#include <stdio.h>
#define MAX 100
The C preprocessor processes directives such as
#include, #define, and conditional compilation
directives before the main compilation stage.
Modular programming divides a larger program into smaller, organized components.
project/
│
├── main.c
├── student.c
├── student.h
├── utility.c
└── utility.h
Functions, source files, and header files can help organize a C project into manageable modules.
Create a complete C application using the concepts learned in this course.
This challenge will help you combine the major concepts of C programming into one practical application.
You have completed the complete 60-lesson C Programming tutorial.
You have studied:
Continue practicing by building your own C programs and gradually increasing their complexity.
Question 1: Which function is the designated entry point of a hosted C program?
Question 2: Which operator is used to obtain the address of an object?
Question 3: Which keyword creates an alternative name for an existing type?
Question 4: Which function is used to release memory allocated dynamically with malloc()?
Question 5: Which statement is used to select among multiple constant cases based on an expression's value?
Question 6: What terminates a C string?
Question 7: Which keyword is used to define a structure?
Question 8: Which preprocessor directive is commonly used to include a header file?
Question 9: Which function is commonly used to open a file?
Question 10: Which function is commonly used to print an error message based on errno?