---
1. Introduction to C Language
History of C: Origin of C, developed by Dennis Ritchie in 1972 at Bell Labs.
Features of C:
Simple and powerful.
Structured programming language.
Portability and efficiency.
Rich library of functions.
Applications of C:
System software development (e.g., Operating Systems).
Embedded systems, gaming, and GUI development.
Structure of a C Program:
#include<stdio.h> // Header file inclusion
int main() { // Main function
// Code
return 0; // Return statement
}
---
2. Basics of C Programming
How to Write and Run a C Program:
1. Use an IDE like Turbo C, Dev-C++, or GCC compiler.
2. Steps: Write -> Compile -> Run -> Debug.
C Syntax:
Case-sensitive language.
Statements end with a semicolon (;).
Code blocks enclosed in { }.
Comments:
Single-line: // This is a comment.
Multi-line: /* This is a multi-line comment */.
---
3. Variables, Data Types, and Operators
Variables:
Definition: Containers to store data.
Declaration: int age;, float temperature;.
Initialization: int age = 16;.
Data Types:
Primitive: int, float, char, double.
Size and range of data types (varies by compiler).
Constants:
Using #define: #define PI 3.14.
Using const: const int maxScore = 100;.
Operators:
Arithmetic: +, -, *, /, %.
Relational: ==, !=, >, <, >=, <=.
Logical: &&, ||, !.
Assignment: =, +=, -=.
Increment/Decrement: ++, --.
---
4. Input and Output Operations
Input/Output Functions:
Input: scanf("%d", &variable);
Output: printf("Result is %d", variable);
Formatting Strings:
%d for integers.
%f for floats.
%c for characters.
%s for strings.
Example:
int a;
printf("Enter a number: ");
scanf("%d", &a);
printf("You entered: %d", a);
---
5. Control Structures
Decision-Making Statements:
if:
if (condition) {
// Code to execute if condition is true
}
if-else:
if (condition) {
// Code if true
} else {
// Code if false
}
nested if: Multiple if statements inside another if.
switch:
switch (variable) {
case value1:
// Code
break;
case value2:
// Code
break;
default:
// Code
}
Loops:
for:
for (int i = 0; i < 10; i++) {
// Code
}
while:
while (condition) {
// Code
}
do-while:
do {
// Code
} while (condition);
---
6. Functions
Definition:
A block of code designed to perform a specific task.
Declaration:
int add(int a, int b); // Function prototype
Calling:
int result = add(5, 3);
Return Statement:
int add(int a, int b) {
return a + b;
}
Advantages:
Code reusability.
Better organization.
---
7. Arrays
Definition:
Collection of elements of the same data type stored at contiguous memory locations.
Declaration:
int numbers[5];
Initialization:
int numbers[5] = {1, 2, 3, 4, 5};
Accessing Elements:
printf("%d", numbers[0]); // Prints 1
Use in Loops:
for (int i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}
---
8. Practical Examples
1. Write a program to calculate the area of a circle.
2. Create a program to find the largest of three numbers using if-else.
3. Write a program to print multiplication tables using loops.
4. Use an array to store marks of 5 students and calculate the average.
Would you like help with practice questions or additional resources for teaching?