0% found this document useful (0 votes)
1 views8 pages

Basic C Programming Expanded

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views8 pages

Basic C Programming Expanded

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Basic C Programming - Expanded Version

For Beginners - English Version


Lesson 1: Introduction to C
C is a powerful, efficient, and portable programming language. It is often referred
to as the 'mother' of modern programming languages because many other
languages, such as C++, Java, and Python, are influenced by it. C is widely used
in developing operating systems, embedded systems, and other
performance-critical applications.
Key Features of C:
- Simple and easy to learn syntax.
- Compiled language, resulting in faster execution.
- Low-level access to memory via pointers.
- Allows direct manipulation of hardware, making it suitable for system
programming.
Lesson 2: Writing Your First C Program
Every C program starts with a `main` function. This is where the program begins
execution. You can include libraries using `#include` to use built-in functions like
`printf()` for printing output.
Example program:
#include int main() { printf("Hello, world!\n"); return 0; }

Explanation of each line:


- `#include `: This tells the compiler to include the standard input/output header file,
which contains the declaration for `printf()` and other standard functions.
- `int main()`: This is the entry point of the program. The program starts executing
from this function.
- `printf(...)`: A function used to print text to the output screen. In this case, it prints
'Hello, world!'.
- `return 0;`: Ends the main function and returns 0 to the operating system, which
indicates that the program finished successfully.
Lesson 3: Variables and Data Types
Variables are used to store data in a program. Before using a variable in C, you
must declare it with a data type. The data type tells the compiler what type of value
the variable will store.
Common data types include:
- `int`: Used for integers like 1, -3, 100.
- `float`: Used for decimal values like 3.14, 9.81.
- `char`: Stores a single character such as 'A', 'b', '9'.
- `double`: Similar to float but with double precision (more accurate decimals).
Example declarations:
int age = 20; float height = 5.9; char grade = 'A';

In this example, we declare an integer variable `age`, a float variable `height`, and
a character variable `grade`. Each variable is assigned a value.
Lesson 4: Conditional Statements
Conditional statements allow your program to make decisions and execute certain
parts of the code based on whether a condition is true or false.
The basic structure of an if-else statement is:
if (condition) { // Code to run if condition is true } else { // Code to run if
condition is false }

Example:
int age = 18; if (age >= 18) { printf("You are an adult.\n"); } else { printf("You
are a minor.\n"); }

In this program, the condition `age >= 18` is evaluated. If it is true, it prints 'You are
an adult.', otherwise it prints 'You are a minor.'
Lesson 5: Loops
Loops are used to execute a block of code repeatedly. This is useful when you
want to perform an operation multiple times without writing the code again and
again.
Types of loops in C:
- `for` loop: Used when the number of iterations is known.
- `while` loop: Used when the condition is checked before each iteration.
- `do-while` loop: Like while loop, but guarantees at least one execution.
Example of a `for` loop:
for (int i = 1; i <= 5; i++) { printf("%d\n", i); }

This loop starts with `i = 1` and continues until `i <= 5`. After each iteration, `i` is
increased by 1. The result is that numbers from 1 to 5 are printed.
Lesson 6: Functions
Functions help you break down your program into smaller, reusable parts. A
function takes input, performs an operation, and may return a result.
Basic structure of a function:
return_type function_name(parameters) { // code }

Example:
void greet() { printf("Welcome!\n"); } int main() { greet(); return 0; }

Here, `greet()` is a user-defined function that prints a message. It is called from


`main()`. The `void` keyword indicates that the function does not return a value.
End of Basic C Programming Module
This expanded version gives deeper explanation for each concept. You can now use this material
for classroom teaching or personal study. Feel free to share or print.

You might also like