1️⃣ Explain Algorithm with Example and Properties.
Definition:
Algorithm is a step-by-step procedure to solve a problem in a finite number of steps.
Example: Add two numbers
-
Start
-
Read two numbers, A and B
-
Calculate Sum = A + B
-
Print Sum
-
Stop
Properties of a good algorithm:
-
Input: Accepts zero or more inputs
-
Output: Produces at least one output
-
Definiteness: Steps are clear and unambiguous
-
Finiteness: Algorithm must terminate after finite steps
-
Effectiveness: Steps are basic, feasible, and solvable manually or by machine
2️⃣ Draw Flowchart and Explain Sum of First 10 Numbers
Explanation:
-
Initialize
i=1andsum=0. -
Check condition
i ≤ 10. -
Add
itosumand incrementi. -
Repeat until
i > 10. -
Print final
sumand stop.
3️⃣ Explain Compilation & Execution Process in C
Steps:
-
Editing: Write source code in
.cfile. -
Preprocessing: Removes comments, expands macros, includes header files.
-
Compilation: Converts source code to assembly code.
-
Assembly: Converts assembly code into object code (
.ofile). -
Linking: Combines object code with libraries to produce executable.
-
Execution: OS loads and runs the executable file.
Example:
4️⃣ Explain Keywords, Identifiers, and Constants in C
Keywords: Reserved words in C with predefined meaning.
Example: int, float, if, else, return
Identifiers: User-defined names for variables, functions, arrays, etc.
Example: sum, age, myFunction
Constants: Fixed values that do not change.
Example: #define PI 3.14 or const int x = 5;
Difference between Keywords and Identifiers:
| Keywords | Identifiers |
|---|---|
| Reserved by C | User-defined names |
| Cannot be used as variable names | Can be used as variable or function names |
| Example: int, float | Example: sum, age |
5️⃣ Explain Operators in C with Examples
Types of operators:
-
Arithmetic:
+ - * / % -
Unary:
++ -- -
Relational/Logical:
> < == != && || ! -
Bitwise:
& | ^ << >> -
Assignment:
= += -= *= /= %= -
Conditional:
?:
Examples:
Precedence & Associativity:
-
Precedence decides which operator evaluated first
-
Associativity decides order for operators with same precedence
Example:
Unit 2: Control Structures, Functions, Arrays
6️⃣ Explain Control Structures in C with Examples
Definition: Control structures manage the flow of execution in a program.
Types:
-
Sequential: Statements executed line by line.
-
Decision Making (Selection):
if, if-else, switch-case -
Loops (Iteration):
for, while, do-while -
Jump Statements:
break, continue, goto
Examples:
For Loop (Factorial):
While Loop (Even Numbers):
7️⃣ Explain Functions in C with Types and Examples
Definition: Block of code that performs a specific task and can be reused.
Advantages: Code reusability, easy debugging, modularity
Types:
-
Library functions:
printf(), scanf() -
User-defined functions
Categories based on arguments & return type:
-
No arguments, no return:
-
Arguments, no return:
-
No arguments, return value:
-
Arguments & return:
Call by value vs Call by reference:
-
Call by value → function gets a copy, original variable not changed
-
Call by reference → function gets address, original variable can be changed
8️⃣ Explain Arrays in C with Examples
Definition: Array = collection of elements of same type in contiguous memory.
Types:
-
1D Array:
int arr[5]={1,2,3,4,5}; -
2D Array:
int mat[2][2]={{1,2},{3,4}}; -
Multidimensional Array
Example Programs:
Sum of 1D Array:
Matrix Addition (2D Array):
9️⃣ Program Based Long Questions
-
Factorial using recursion:
-
Sum of first 10 numbers using loop & function:
-
Matrix addition program → See 2D array example above.
-
Demonstrate Bitwise Operators: