In the last post, we employed dynamic memory allocation. Today, we're looking at that concept in further detail.
The function malloc() - memory allocate pulls a section of the heap - memory that exists outside of the usual program stack which is used to store data members - and returns it to you. The
Preparing the next post is taking too long. It'll be ready by Monday, at
We now understand (at least a little bit) how we can work with pointers. We're now going to look at one of the simplest, but most useful, data storage structures - the Linked List
Referencing a Pointer
Before we go any further, we need to look at a bit of syntax. We know that when we
We've dealt with arrays a little bit in the past. Did you know that that whole time, we were dealing with pointers?
Array as a Pointer
When we declare an array, we are really doing the following things:
Allocating a section of memory large enough to contain N objects of the chosen data type
Creating a pointer to
You've likely noticed the * symbol showing up in our code. Time to look at what that means.
Value and Reference
There are two kinds of data in a program: values, references to a value. We already know how to create a value object, because basic data types such as int and char are value objects.
This will be a bit of a longer section, because I couldn't think of a fun way to write the code otherwise. Bonus!
A structure is a data element defined by the programmer which contains several member data elements. We define these structures to allow ourselves to handle a set of related data much more
Ever wondered what the whole #include thing really means? Of course you have.
There are basically three stages that gcc goes through when it compiles your program: precompilation, translation, and linking. At this point, we're interested in that first stage.
The precompiler is the program which reads and organizes your C code for the translator to
We know how to send input from the terminal. Now we'll look at the right and wrong ways to do keyboard input within your program.
Reading Input from Standard Input
Have you ever seen a program which used a prompt to ask for something? For a simple case, it could look like this:
There are numerous functions
Forgot to post before I went out drinking. Will have to play catch up
It's finally time to look at those arguments we pass into main() - int argc and char *argv.
You might have noticed that vi and gcc are both programs. You might also have noticed that we always call these programs with arguments.
You might also notice that, up to this point, we haven't called any