Monday, 31 March 2014

Clearing Confusion....

Hi all,

I recently had a few people point out that I was a bit unclear as to my C++ experience. I am NOT an industry working C++ programmer who has designed sophisticated programs. No, a lot of my C++ knowledge comes from my professors and researching on the internet. I am always accepting new information but please understand that once in a while, you may see a "bad design" or "outdated code usage" here and there. Let me know, and I will address the problem, immediately.

I do offer C++ tutoring services because I DO know the C++ language very well and more importantly, I know how a beginner programmer thinks and his/her problems and stumbling blocks. I offer these services, only because I want to help you learn. If for some reason, you think that I am not giving you the knowledge/experience that you need, I will always refund the money to you and do my best to help you find a replacement for me.

In the future, I will be posting more articles and tutorials and will still continue to accept people for tutoring. However, I want to be clear on one thing: my main goal is to help the beginner and somewhat intermediate C++ programmers; not the experts who want to learn sophisticated concepts/code.

I am sorry for the confusion if I have caused any and I promise that I still will do my best to help each and every one of you that comes to me.

Thank you,
Joe

Friday, 28 March 2014

The "Stack"

Since a lot of beginning programmers rarely hear of the 'stack' (if they even hear about it), I thought I'd post a somewhat introductory description of what the stack is.

  What is the stack? The stack is an area of memory that the operating system gives to you when your program starts up. It is used to hold all of your function’s local variables and parameters. Why is it called a stack? In truth, the stack is not “a stack” but just a chunk of memory we use. However, we do ‘conceptually’ think of it as a stack to aid in understanding it. More specifically, we ‘imagine’ the stack as looking like this:

Now, what’s the green arrow? That is the “stack pointer.” Our program uses it to keep track of where the top of the stack is. Anything below the stack pointer is memory that is in use (either for variables, parameters or something); the memory above the stack pointer is completely free. Everytime we add something to the stack, the pointer goes up until it’s right above the top of the newly added data. This way, our programs can keep track of what’s on the stack and where it can start adding new data onto the stack. Also, you’ll hear these words popping up in your programming studies, so here they are:

“Push” – Means to add something onto the top of the stack.
“Pop” – Means to remove something from the top of the stack.

There is no going “in-between” or “from the bottom.” A stack is a stack. You can only add something to the top or remove something from the top.

Here’s a sample program that should help you understand:

int add(int x, int y)
{
return x + y;
}

int main()
{
  int x;
  int y;
  add(x, y);
  return 0;
}

This is what the stack looks like:
Now when the line: int x; gets executed, the computer makes room on the stack by simply moving the stack pointer UP like:

As you can see, the stack pointer is now on top of the local variable ‘x’.
When int y; executes, ‘y’ will get “pushed” onto the stack making the stack look like:


Now, the function call to add() gets executed: add(x, y);
And we pass in x and y BY VALUE. When we say BY VALUE, a copy of x and y will be put onto the stack like this:


As you can see, add()’s parameters: x and y, ARE variables, BUT they are separate variables with their own copies of the data you pass in. When the add() function’s return statement executes, then the stack pointer “goes back down” indicating that the memory above it is now available. Some people also say that the parameters are “popped” off the stack. So, now the stack looks like this:


As you can see, the memory originally used for add()’s parameters are now “deallocated” – made available for use again. What is the stack pointer? It is merely a variable that contains the starting “address” of the available memory on the stack. Remember that each “byte” of memory has an address (just a number) associated with it. The stack pointer contains the address of the first byte of available free space on the stack. All the other bytes “on top” of this one byte of free space, is free too; all the other bytes “below” this byte is being used.

I hope this helps. Remember that this is just a basic introduction. There are lots of other information out there that you can research. If you need to ask a question, email me at:

sparkprogrammer@gmail.com
Joe – C++ tutor

Thursday, 27 March 2014

First Post

Hi all,

I recently decided to create a blog about computer programming, SQL and my own projects (thus the phrase "Grape" ideas.

I plan on posting certain tutorials on programming, explanations, etc...

Hope you enjoy them and find them useful!

A special thank you to my "first and always" lover who helped me name my blog.

Joe