FOP_Exam
FOP_Exam
• Diamond: Decision
• Parallelogram: Input/Output
• Arithmetic Operators: +, -, *, /, %
➔ Pre-increment vs Post-increment:
➔ Basic Datatypes in C:
• int: Integer
• char: Character
FOP
➔ Process of Compilation in C:
• Linking: Links various code files and libraries into a single executable.
#include <stdio.h>
int main() {
// Code
return 0;
➔ Conditional Statements in C:
• 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:
➔ String Functions in C:
➔ Mathematical Functions in C:
➔ Nested Looping: A loop within another loop. Used for multi-dimensional data
structures like matrices.
// Code
}
FOP
➔ Prime Number:
• Algorithm:
o Input number
• Flowchart:
Start -> Input number -> (Diamond) Check divisibility -> No: Prime -> Yes: Not Prime -> End
#include <stdio.h>
#include <math.h>
int main() {
scanf("%d", &num);
if (num % i == 0) {
flag = 1;
break;
if (flag == 0) {
} else {
return 0;
int arr[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
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
// Function definition
return a + b;
➔ Types of Functions:
int factorial(int n) {
if (n == 0)
return 1;
else
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
// 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;
Union: Similar to structure, but only one member can hold a value at a time.
union Data {
int i;
float f;
char str[20];
};
struct Person {
char name[50];
struct Address addr;
};