FOP
➔ Flowchart: A flowchart is a diagram that represents a process or algorithm. It uses
standardized symbols to describe the steps and their order. Common symbols
include:
• Oval: Start or end
• Rectangle: Process or operation
• Diamond: Decision
• Parallelogram: Input/Output
• Arrow: Flow of control
➔ Difference Between Algorithm and Flowchart:
• Algorithm: Step-by-step written instructions to solve a problem.
• Flowchart: A visual representation of an algorithm using symbols.
➔ Operators in C: Operators are symbols that perform operations on variables and
values. Types include:
• Arithmetic Operators: +, -, *, /, %
• Relational Operators: ==, !=, >, <, >=, <=
• Logical Operators: &&, ||, !
• Assignment Operators: =, +=, -=, *=, /=
• Increment/Decrement Operators: ++, --
• Bitwise Operators: &, |, ^, ~, <<, >>
➔ Pre-increment vs Post-increment:
• Pre-increment: ++x increments the value before using it.
• Post-increment: x++ uses the value before incrementing it.
➔ Basic Datatypes in C:
• int: Integer
• float: Floating-point number
• double: Double-precision floating-point number
• char: Character
FOP
➔ Process of Compilation in C:
• Preprocessing: Handles directives like #include and #define.
• Compilation: Translates code to assembly language.
• Assembly: Converts assembly code to machine code.
• Linking: Links various code files and libraries into a single executable.
➔ Basic Structure of a C Program:
#include <stdio.h>
int main() {
// Code
return 0;
➔ Conditional Statements in C:
• if: Executes a block of code if a condition is true.
• else if: Checks another condition if the previous if is false.
• else: Executes a block of code if none of the conditions are true.
• switch: Selects one of many blocks of code to be executed.
➔ Entry Control Loop and Exit Control Loop:
• Entry Control Loop: Condition is checked before the loop starts. (for, while)
• Exit Control Loop: Condition is checked after the loop executes. (do-while)
Difference: Entry control loops might not execute if the condition is false initially; exit
control loops will execute at least once.
➔ Switch Statement in C: Used for selecting one of many blocks of code to execute.
switch (expression) {
case value1:
// Code
break;
FOP
case value2:
// Code
break;
default:
// Code
Rules:
• The expression must be an integer or character.
• Use break to prevent fall-through.
• default is optional but handles cases not matched by case.
➔ Formatted and Unformatted I/O Statements:
• Formatted I/O: Uses printf, scanf for formatted output/input.
• Unformatted I/O: Uses getchar, putchar for unformatted character input/output.
➔ String Functions in C:
• strcpy(), strcat(), strlen(), strcmp()
➔ Mathematical Functions in C:
• sqrt(), pow(), abs(), sin(), cos(), tan()
➔ Nested Looping: A loop within another loop. Used for multi-dimensional data
structures like matrices.
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
// Code
}
FOP
➔ Prime Number:
• Algorithm:
o Input number
o Check divisibility from 2 to sqrt(number)
o If divisible by any, it’s not prime
o Else, it’s prime
• Flowchart:
Start -> Input number -> (Diamond) Check divisibility -> No: Prime -> Yes: Not Prime -> End
Example Prime Number
#include <stdio.h>
#include <math.h>
int main() {
int num, flag = 0;
printf("Enter a number: ");
scanf("%d", &num);
for (int i = 2; i <= sqrt(num); i++) {
if (num % i == 0) {
flag = 1;
break;
if (flag == 0) {
printf("%d is a prime number.\n", num);
} else {
printf("%d is not a prime number.\n", num);
FOP
}
return 0;
➔ Array in C: An array is a collection of elements of the same data type stored in
contiguous memory locations. There are different types of arrays in C:
One-dimensional Array: A linear list of elements.
int arr[5] = {1, 2, 3, 4, 5};
Multi-dimensional Array: Arrays of arrays. The most common form is a two-dimensional
array.
int arr[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
➔ Array of String: An array of strings is essentially a two-dimensional array where
each row represents a string.
char names[3][10] = {
"Alice",
"Bob",
"Charlie"
};
➔ Array Storage in Memory: Arrays are stored in contiguous memory locations. For a
one-dimensional array, the elements are stored sequentially in memory. For a two-
dimensional array, elements are stored row-wise.
➔ Modular Programming: Modular programming is a software design technique that
emphasizes separating the functionality of a program into independent,
interchangeable modules. It can be achieved by dividing the program into functions
and using header files for declarations.
FOP
➔ Function in C: A function is a self-contained block of code that performs a specific
task. It can be defined as:
// Function declaration
int add(int, int);
// Function definition
int add(int a, int b) {
return a + b;
// Using the function
int result = add(2, 3);
➔ Types of Functions:
• Standard Library Functions: Provided by C library, e.g., printf(), scanf().
• User-defined Functions: Created by the programmer for specific tasks.
➔ Recursive Function: A recursive function is a function that calls itself. Example:
int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
➔ Command Line Argument: Command line arguments are parameters passed to
the program when it is executed. They can be accessed in main function.
int main(int argc, char *argv[]) {
for (int i = 0; i < argc; i++) {
printf("Argument %d: %s\n", i, argv[i]);
FOP
}
return 0;
➔ Scope of Data: The scope of a variable determines its visibility within the code. For
example:
int globalVar = 10; // Global scope
void function() {
int localVar = 20; // Local scope
printf("%d\n", localVar); // Accessible here
}
int main() {
printf("%d\n", globalVar); // Accessible here
function();
// printf("%d\n", localVar); // Error: localVar not accessible
return 0;
}
➔ Pointer and Pointer to Pointer: A pointer is a variable that stores the memory
address of another variable. A pointer to a pointer is a variable that stores the
address of another pointer.
int a = 10;
int *ptr = &a; // Pointer to int
int **ptr2 = &ptr; // Pointer to pointer to int
➔ Difference Between Call by Value and Call by Reference:
• Call by Value: Passes a copy of the argument's value. Changes made to the
parameter inside the function do not affect the argument.
• Call by Reference: Passes the argument's address. Changes made to the
parameter affect the argument.
// Call by Value
void modifyValue(int x) {
x = 10;
}
FOP
// Call by Reference
void modifyReference(int *x) {
*x = 10;
}
➔ Pointer and Array: A pointer can be used to iterate through the elements of an array.
int arr[5] = {1, 2, 3, 4, 5};
int *ptr = arr;
for (int i = 0; i < 5; i++) {
printf("%d ", *(ptr + i));
}
➔ Pointer to Function: A pointer to a function points to the address of a function,
allowing the function to be called indirectly.
void func(int a) {
printf("%d\n", a);
}
void (*funcPtr)(int) = func;
funcPtr(10); // Calls func(10)
➔ Dynamic Memory Allocation: Allocates memory during runtime using functions
like malloc(), calloc(), realloc(), and free().
int *ptr = (int *)malloc(5 * sizeof(int)); //only this change in code
if (ptr == NULL) {
printf("Memory not allocated.\n");
} else {
// Use the allocated memory
free(ptr); // Deallocate memory
}
➔ User Defined Datatype: Structure and Union:
• Structure: A collection of variables of different types under a single name.
struct Person {
char name[50];
int age;
FOP
};
Union: Similar to structure, but only one member can hold a value at a time.
union Data {
int i;
float f;
char str[20];
};
➔ Difference Between Union and Structure:
• Structure: Allocates memory for all members separately.
• Union: Allocates memory equal to the largest member.
➔ Nested Structure: A structure within another structure.
struct Address {
char city[50];
int pin;
};
struct Person {
char name[50];
struct Address addr;
};
➔ Types of Files and Implementation in C:
• Text Files: Store data as readable text.
FILE *file = fopen("example.txt", "r");
• Binary Files: Store data in binary format.
FILE *file = fopen("example.bin", "rb");
➔ File Management Functions:
• fopen(), fclose(), fread(), fwrite(), fprintf(), fscanf(), fseek(), ftell()
➔ sizeof() Operator: Returns the size of a datatype or variable.
int a;
printf("%lu", sizeof(a)); // Output: size of int
FOP
➔ Storage Classes in C:
• auto: Default storage class for local variables.
• register: Stores variables in CPU registers for faster access.
• static: Retains the value of a variable between function calls.
• extern: Declares a global variable defined in another file.
➔ Bitwise Operators: Perform operations on bits.
int a = 5; // 0101 in binary
int b = 3; // 0011 in binary
int c = a & b; // 0001 (1 in decimal)
➔ Preprocessor: Preprocesses the source code before compilation. Example:
#define PI 3.14
➔ Common Errors in C and Solutions:
• Syntax Error: Fix code syntax.
• Segmentation Fault: Check pointers and memory access.
• Compilation Error: Review error messages and fix code.
• Linker Error: Ensure correct linking of libraries and functions.