Pulling in all the stack items mentioned in last week’s Lesson, I present to you a C program that emulates stack storage. I’m certain this presentation will be one of the highlights of your programming career.
Continue reading
Category Archives: Lesson
Behold the Stack, Part IV
To simulate stack storage in a C program, you need to emulate the four basic parts of a stack:
- The stack storage
- A stack pointer
- A function to push a value onto the stack
- A function to pop a value from the stack
Further, you need to implement controls that prevent a stack overflow or underflow. And you can get real fancy, but those four items are the basics.
Continue reading
Behold the Stack, Part III
Whether you simulate a stack in your C code or just ignore the concept altogether, your program constantly uses the processor’s stack. Specifically, if the code contains a function, it uses this stack not only to call and return from the function, but to pass and return arguments as well.
Continue reading
Behold the Stack, Part II
At the lowest programming level, you encounter machine code. This is the language of the processor itself. Machine code directs the processor to do things, such as read from or write to memory, store data, perform math, and other tasks. And if you dare to program a processor directly, you’ll encounter something called the stack pointer register.
Continue reading
Behold the Stack, Part I

One of those weirdo programming concepts university sophomore programming students eagerly avoid is the stack. It’s a type of storage with unique features, but it’s difficult to appreciate unless you understand its origins.
Continue reading
The abs() Function
Seriously, why do programmers need an abs() function? It’s available in just about every programming language; if you view an alphabetic list of functions, abs() is probably the first one. Yet, what’s the point of a function that simply converts negative values to positive values?
Continue reading
Yes, You Can Nest while Loops
Somewhere in my vast array of teaching material, I claimed that only for loops can be nested. That’s poppycock.
Continue reading
A scanf() String Trick
I’m not a fan of the scanf() function, despite how handy it can be. It’s a great teaching tool, but for a program that accepts string input, you need to use fgets() instead. Still, scanf() can be used to read a string, providing that you know the whitespace requirements beforehand.
Continue reading
Looping Variables End Value
I received a question on a looping variable and why its value after the loop isn’t the same as the ending value of the loop. It’s a puzzling issue I remember from when I first learned to program, but one that you can understand once you figure out what the loop does.
Continue reading
Hunting for a Library
To add more functionality to the C language, you mix in another library. The library contains routines (functions) that let you control specific hardware, manipulate data, work with graphics, and a host of other capabilities beyond the standard C library.
Continue reading