C is a general-purpose programming language used to create software, operating systems, embedded systems, games, utilities, and many other types of applications.
C is one of the most important programming languages for beginners because it helps students understand programming fundamentals such as variables, data types, operators, conditions, loops, functions, arrays, pointers, structures, and memory management.
C is a general-purpose, procedural programming language. It was designed to provide a simple and efficient way to write computer programs.
C allows programmers to work with both high-level programming concepts and low-level computer operations.
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
The above program displays Hello World.
Learning C gives students a strong foundation in programming.
C teaches how a program works at a fundamental level.
C was developed by Dennis Ritchie at Bell Labs.
The language was developed during the early 1970s and became an important language for system software development.
C was closely associated with the development of the UNIX operating system.
C is called a general-purpose programming language because it can be used for many different types of software.
C primarily follows the procedural programming approach.
A program can be divided into functions or procedures that perform specific tasks.
#include <stdio.h>
void message()
{
printf("Welcome to C");
}
int main()
{
message();
return 0;
}
Here, message() is a function that performs a specific task.
C programs are normally compiled before they are executed.
A compiler translates the C source code into machine code that the computer can execute.
Source Code
↓
Compiler
↓
Machine Code
↓
Program Execution
The instructions written by a programmer are called source code.
C source files normally use the .c extension.
hello.c
A C compiler processes this source file to create an executable program.
Let's look at a simple C program.
#include <stdio.h>
int main()
{
printf("Hello World");
return 0;
}
This program displays:
Hello World
The main() function is the entry point of a C program.
Execution begins from the main() function.
int main()
{
printf("Hello");
return 0;
}
A program can contain many functions, but execution starts from
main().
The #include directive is used to include a header file in a
C program.
#include <stdio.h>
The stdio.h header provides declarations for standard input
and output functions such as printf() and scanf().
stdio.h is a standard C header file related to input and
output operations.
It contains declarations for functions such as:
printf()scanf()getchar()putchar()#include <stdio.h>
The printf() function is commonly used to display output.
#include <stdio.h>
int main()
{
printf("Welcome to C Programming");
return 0;
}
Output:
Welcome to C Programming
A statement is an instruction that tells the computer to perform an operation.
Most C statements end with a semicolon ;.
printf("Hello");
return 0;
The semicolon marks the end of these statements.
Curly braces { } are used to define a block of code.
int main()
{
printf("Hello");
return 0;
}
The statements inside the braces belong to the main()
function.
Comments are notes written inside source code. They are ignored by the compiler.
Single-line comment:
// This is a comment
Multi-line comment:
/*
This is a
multi-line comment
*/
A variable is a named memory location used to store data.
int age = 20;
Here:
int is the data type.age is the variable name.20 is the value.A data type tells the compiler what type of data a variable can store.
Common C data types include:
int – integer valuesfloat – floating-point valuesdouble – double-precision floating-point valueschar – character valuesint age = 20;
float price = 25.50;
char grade = 'A';
The scanf() function can be used to take formatted input from
the user.
#include <stdio.h>
int main()
{
int age;
printf("Enter age: ");
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
Operators are symbols used to perform operations on values and variables.
Examples include:
+
-
*
/
%
==
>
<
C provides arithmetic, relational, logical, assignment, bitwise, and other operators.
Conditional statements allow a program to make decisions.
int age = 20;
if(age >= 18)
{
printf("Adult");
}
The if statement executes its block when the condition is
true.
Loops are used to execute a block of code repeatedly.
Common loops in C are:
for loopwhile loopdo-while loopfor(int i = 1; i <= 5; i++)
{
printf("%d\n", i);
}
A function is a block of code designed to perform a particular task.
void hello()
{
printf("Hello");
}
Functions help divide a large program into smaller and reusable parts.
An array stores multiple values of the same type under one variable name.
int numbers[5] = {
10, 20, 30, 40, 50
};
Array indexing normally starts from 0.
printf("%d", numbers[0]);
A string in C is stored as an array of characters terminated by a null character.
char name[] = "Rahul";
printf("%s", name);
The %s format specifier is commonly used with strings in
formatted input and output functions.
A pointer is a variable that stores a memory address.
int age = 20;
int *ptr = &age;
Here, ptr stores the address of the variable
age.
Pointers are an important part of C programming.
A structure allows different types of data to be grouped together under one user-defined type.
struct Student
{
int age;
char grade;
};
Structures are useful for representing related information.
C provides functions for working with files.
Common file operations include:
FILE *file;
C is used in many areas of computing.
Learning C can make it easier to understand fundamental programming concepts used in many other languages.
Concepts such as variables, conditions, loops, functions, arrays, and data structures are also found in languages such as C++, Java, C#, and other programming languages.
C also provides a useful foundation for understanding memory and low-level programming concepts.
Throughout this 60-lesson C tutorial, you will gradually learn:
By the end of the course, you will have a strong foundation for writing and understanding C programs.
main() function is the entry point of a C program.stdio.h provides declarations for standard input and output functions.printf() is commonly used for displaying output.scanf() is commonly used for formatted input.Question: Who developed the C programming language at Bell Labs?