๐Ÿ’ป๐Ÿ”ต

C Programming

Building your programming foundation ๐Ÿš€

๐ŸŽ“ BCA โ€ข C PROGRAMMING

๐Ÿ’ป C Programming

Learn C programming from the basics with simple explanations, examples, diagrams, important concepts and exam-friendly notes.

๐Ÿ“š C Programming Topics

๐Ÿ’ป 1. Introduction to C

C is a general-purpose, procedural programming language. It is widely used for system programming, embedded systems and application development.

โญ Basic C Program

#include <stdio.h> int main() { printf("Hello, World!"); return 0; }

๐Ÿ” Important Parts

๐Ÿ“ฆ 2. Variables & Data Types

A variable is a named memory location used to store data.

int age = 20; float marks = 85.5; char grade = 'A';

๐Ÿ”ข Common C Data Types

๐Ÿ”ข int
Integer values
๐Ÿ”ข float
Decimal values
๐Ÿ”ข double
More precise decimal values
๐Ÿ”ค char
Single character
๐Ÿ’ก Example:

int age = 20; stores the integer value 20 in the variable named age.

โž• 3. Operators

Operators are symbols used to perform operations on values and variables.

โž• Arithmetic

+   -   *   /   %

๐Ÿ” Relational

>   <   ==   !=   >=   <=

๐Ÿง  Logical

&&   ||   !

๐Ÿ“ Assignment

=   +=   -=   *=

๐Ÿ’ป Example
int a = 10; int b = 5; int sum = a + b; int product = a * b;

๐Ÿ”€ 4. if-else

The if-else statement is used to make decisions based on a condition.

โ–ถ๏ธ Start
โ†’
๐Ÿ” Condition
โ†’
โœ… True
โ†’
โŒ False
๐Ÿ’ป Example
#include <stdio.h> int main() { int age = 18; if(age >= 18) { printf("Eligible"); } else { printf("Not Eligible"); } return 0; }

๐Ÿ”˜ 5. switch Statement

The switch statement is used when one expression needs to be compared with multiple possible values.

switch(choice) { case 1: printf("Option 1"); break; case 2: printf("Option 2"); break; default: printf("Invalid choice"); }
๐Ÿ’ก Important:

The break statement is commonly used to exit a case.

๐Ÿ” 6. Loops

Loops are used to execute a block of statements repeatedly.

๐Ÿ” for Loop

Useful when the number of repetitions is known.

๐Ÿ”„ while Loop

Checks the condition before execution.

๐Ÿ” do-while Loop

Executes the body at least once.

๐Ÿ’ป for Loop Example
for(int i = 1; i <= 5; i++) { printf("%d\n", i); }

โš™๏ธ 7. Functions

A function is a block of code designed to perform a particular task.

๐Ÿ“ฅ Input
โ†’
โš™๏ธ Function
โ†’
๐Ÿ“ค Return Value
๐Ÿ’ป Function Example
#include <stdio.h> int add(int a, int b) { return a + b; } int main() { int result = add(10, 20); printf("%d", result); return 0; }

โœจ Advantages

๐Ÿ“Š 8. Arrays

An array stores multiple values of the same data type in a contiguous collection.

[0] 10
[1] 20
[2] 30
[3] 40
๐Ÿ’ป Array Example
int marks[5] = {80, 75, 90, 85, 88}; printf("%d", marks[0]);
๐Ÿ’ก Remember:

C array indexing starts from 0.

๐Ÿ”ค 9. Strings

In C, a string is a sequence of characters stored in a character array and terminated by the null character \0.

๐Ÿ’ป String Example
char name[] = "Roshni"; printf("%s", name);

๐Ÿงฐ Common String Functions

๐Ÿ”ข strlen()
Finds string length
๐Ÿ”— strcat()
Joins strings
๐Ÿ“‹ strcpy()
Copies a string
๐Ÿ” strcmp()
Compares strings

๐Ÿ‘‰ 10. Pointers

A pointer is a variable that stores the memory address of another variable.

๐Ÿ“ฆ Variable
value = 10
โ†’
๐Ÿ“ Address
โ†’
๐Ÿ‘‰ Pointer
๐Ÿ’ป Pointer Example
int number = 10; int *ptr = &number; printf("%d", *ptr);
โญ Important Symbols:

& โ†’ address-of operator
* โ†’ dereference operator

๐Ÿ—๏ธ 11. Structures

A structure is a user-defined data type that allows different types of data to be grouped together.

๐Ÿ’ป Structure Example
struct Student { int rollNo; char name[30]; float marks; }; struct Student s1;

๐ŸŽ“ Example Structure

๐Ÿ”ข Roll Number
๐Ÿ”ค Student Name
๐Ÿ“Š Marks
๐ŸŽ“ Course

๐Ÿ“ 12. File Handling

File handling allows a C program to store and retrieve data from files.

๐Ÿ’ป Program
โ†’
๐Ÿ“‚ File
โ†’
๐Ÿ’พ Stored Data

๐Ÿงฐ Common File Functions

๐Ÿ“‚ fopen()
๐Ÿ”’ fclose()
โœ๏ธ fprintf()
๐Ÿ“– fscanf()
๐Ÿ’ป Simple Example
FILE *file; file = fopen("data.txt", "w"); fprintf(file, "Hello C Programming"); fclose(file);

๐Ÿ“ C Programming Quick Revision

๐ŸŽฏ BCA C Programming Exam Checklist

Before your exam, make sure you have revised these important topics:

โœ… C Basics
โœ… Data Types
โœ… Operators
โœ… if-else
โœ… switch
โœ… Loops
โœ… Functions
โœ… Arrays
โœ… Strings
โœ… Pointers
โœ… Structures
โœ… File Handling