LightReader

Chapter 7 - Chapter 7 — The Tool Builder

The robot stood quietly on the screen.

Its small square eyes blinked slowly.

[^_^]

/| |\

/ \

Below the robot, the computer displayed a new message.

SYSTEM PROGRESS: 40%

NEXT MODULE: TOOL CREATION

REQUIREMENT: FUNCTION SYSTEM

Pran leaned back in his chair.

"Tool creation?"

The cursor blinked again.

_

Pran thought about everything he had done so far.

He had taught the computer to:

• print messages• ask questions• store information• make decisions• repeat actions

But every time he wanted the computer to do something new, he had to write the instructions again and again.

That was inefficient.

Imagine building a calculator.

Every time you wanted to add numbers, you would have to rewrite the entire addition logic.

That would be exhausting.

Instead, programmers create functions.

A function is like a tool.

Once you build the tool, you can use it whenever you want.

Think of it like a hammer.

You don't build a new hammer every time you need to hit a nail.

You build it once.

Then you reuse it.

Programming works the same way.

Pran opened the code editor again.

He started typing.

#include

int add(int a, int b) {

return a + b;

}

int main() {

int result;

result = add(5, 3);

printf("Result: %d\n", result);

return 0;

}

He looked at the screen.

"This is interesting."

Let's break it down.

The function begins here.

int add(int a, int b)

This means:

Create a function called add that takes two numbers.

The numbers are called parameters.

Here they are:

a

b

Inside the function we write the instructions.

return a + b;

This tells the computer:

Add the two numbers and return the result.

So if the function receives:

5 and 3

It returns:

8

Simple.

Pran ran the program.

The output appeared.

Result: 8

He smiled.

"That's actually pretty useful."

He tried another version.

result = add(10, 20);

Now the output became:

Result: 30

The same function worked again.

No rewriting needed.

That's the beauty of functions.

You write the logic once, and reuse it forever.

The computer screen flickered again.

A new message appeared.

FUNCTION SYSTEM DETECTED

TOOL CREATION ENABLED

Pran raised an eyebrow.

"Tool creation enabled?"

Another message appeared.

BUILD FIRST TOOL

REQUIREMENT: CALCULATION MODULE

Pran laughed.

"Alright computer. Let's build something."

He wrote another function.

int multiply(int a, int b) {

return a * b;

}

Now his program looked like this.

#include

int add(int a, int b) {

return a + b;

}

int multiply(int a, int b) {

return a * b;

}

int main() {

int result1 = add(4, 6);

int result2 = multiply(3, 5);

printf("Addition: %d\n", result1);

printf("Multiplication: %d\n", result2);

return 0;

}

He ran it.

The screen displayed:

Addition: 10

Multiplication: 15

The robot suddenly moved again.

[^o^]

/| |\

/ \

Another system message appeared.

TOOL BUILDER MODULE ACTIVATED

Then another.

SYSTEM PROGRESS: 60%

Pran leaned forward.

"Sixty percent?"

The computer was unlocking more systems.

Another message appeared.

NEXT MODULE: MEMORY STORAGE

Pran frowned.

"Memory storage?"

Then the computer displayed something strange.

VARIABLE MEMORY MAP DETECTED

ACCESSING ADDRESS SYSTEM

Pran blinked.

"Address system?"

The screen printed one final line.

POINTER ACCESS REQUIRED

Pran scratched his head.

"Pointers?"

He had heard programmers talk about pointers before.

Usually they said things like:

"Pointers are confusing."

Or:

"Pointers make programmers cry."

Or sometimes:

"Pointers are powerful… but dangerous."

Pran cracked his knuckles.

"Well," he said.

"If this computer wants pointers…"

"Then we're going to learn how memory works."

The cursor blinked again.

_

Waiting.

Silent.

Ready for the next lesson.

Chapter 8 — The Memory Vault

This chapter introduces something that many beginners find mysterious.

You will learn:

memory addresses

pointers

the & operator

the * operator

More Chapters