End of This Site

I’ve found C++ to be thoroughly fun and enjoyable, but it’s too complicated for me. This doesn’t mean I’m giving up, I’m planning on trying Python next, oh gosh, hope it’s easier to grasp!

33) Utilizing Arrays in Functions

Arrays are good for storing information and accessing information quick, but what else can you use it for? Well the answer is a lot of things, things that I don’t want to cover here, but one thing is CAN be used for, is as the parameter for a function. First thing you need to know is that you can take all the memory an array uses, and GIVE them to a function, you need to go through certain steps to reach that final goal; and guess what I’m going to explain? Just the “certain steps to reach that final goal” that’s all, so let’s wrap up this introduction and start with the actual “steps.”

3 things are needed to use an array as a function’s parameter:

  1. The array’s type
  2. The array’s name 
  3. Void brackets

Let’s start with #1, this is easy, it’s the same type as the array you want to incorporate into the function; such as int  or float . 

On to #2, as would any parameter, it has to have a name right? So name it whatever you want (preferably not the name of your original array that you’re incorporating).

Finally is #3 with is just two empty brackets [] which are empty, they’re void!

Let’s have a live example here followed by a small challenge shall?

void examplearray (int array[])

Try and create a void function “test” with the integer array “hi” as the parameter (I know it’s not really much of a challenge but heck I tried).

What you should have gotten was the following:
void test (int hi[])

Simple right? Any further questions can be emailed or commented, have fun!

PS – Much apologies for this slow post, it’s our school’s essay time of the year so I’m been busying myself with that kinda stuff…

32) Utilizing Arrays

As from the previous post, you’ve seen how to initialize a simple array (silent yay!), but how do you actually use an array? Well to first utilize it, you have to understand the concept of an array, and by concept, I don’t mean an essay explaining its history, I mean how it does its job. As explained before, it stores data, these data values are stored in “elements” and we can access these elements. But here’s one thing you should know, the third value in an array would be accessed like:

x = array[2];

Why? well look at the following chart:

Just saying you might want to go look at the words that the arrows point to (if you haven’t already).

NOTE: initializing arrays always have a “type” before them such as “int” where as accessing the array has no “type” before the array name.

For further information and other ways to utilize arrays, visit http://cplusplus.com/doc/tutorial/arrays/ and press Ctrl+F (aka “Find”) and type “Accessing the values of an array.”

Good luck and have fun!

31) An Array of Data: Initialization

Last post was the end of the basics of functions… This post starts the data legacy, where I’ll be covering information about different types of data and how to use them! Starting off our new “legacy” as I’ll call it, is probably the most commonly used and heard of member, the Arrays!

Programming wise it is: “An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.” (taken from cplusplus.com)

But that sounds awfully confusing right? Well here are some points you need to understand:

  1. Contiguous means touching, which in this case means next to each other; or adjacent
  2. Arrays are a collection of variables all of the same type
  3. They are stored under a common name
  4. Arrays can store up to just about as much variables as you’ll need.

So isn’t it about time we get down to business? We got an array of stuff to cover (excuse the pun, I’m feeling punny right now)!

The structure of an array is:

type name [element] = { value, value, value… }

Now to break it down:

  1. type – the type of array it’ll be (int, float, double, etc.)
  2. name – how the array will be called, identified as, and referred to as
  3. [element] – number of variables the array holds
  4. { value, value, value } – if you want to set initial values to the variables, here’s where you set them

NOTE: [element] can be left blank as long as the { value, value, value } part is filled, in that case [element] will equal the number of values you enter.

A full initialized array would look something like the following:

int herp [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Pretty simple right? Good luck and have fun (and for those in high school who live in California, good luck with the CAHSEE!)!

30) A Month Delayed Chart: Operators and Equality!

First off (actually last off, I just realized the number as I was about to post this), this is the 30th informational post (I think unless I forgot to number one)! I was recently scrolling through my posts to see what I lacked and guess what? I forgot to include one of the most fundamental charts/information, the operators and ways of comparing values. Now if that sounds confusing, just remember those signs from Algebra II about inequalities and stuff. That’s thingies I’m talking about (and for some reason my computer recognizes “thingies” as an actual word..?).

So here are the charts followed by their usage (borrowed from “cpusplus.com”):

(Sorry if the pictures are on the small side, I’m not a fanatic for “Paint” or photo-editing in general)

NOTE: Modulo – is the term used to divide a number by another, and collect their remainder ) represented by the percent symbol %. For example:
x=22 % 3;
“X” in this case would be equal to 1 because 22/3 equals 7 remainder 1.

And following our charts are the usages (most are just like how you’d use them on a calculator):

Addition: x+1
Subtraction: x-1
Division: x/2
Modulo: x % 2

The equality signs will most commonly used in “if-else” statements so that’s how I’ll show them:

Equal to: if (x==10)
Not Equal to: if (x!=10)
Greater Than: if (x>10)
Less Than: if (x<10)
Greater Than or Equal to: if (x>=10)
Less Than or Equal to: if (x<=10)

And there you have it, the basic operators!

29) Recursivity: A Loop-Function

So I’ve finally got some time to get up to date with the blog (personal yay), and so you’ve hopefully tried using functions. What you’ll probably notice is that every time you want to use a function, you have to call on it right? Well what if you can have a function that repeats itself until it stops… like a loop? Well it’s here that “recursivity” comes into play. Now if you type that into any text editor Windows will say it’s not a real word, that’s technically true because it’s total jargon. Back to recursivity, the basic concept is a function calling on itself until a  condition is fulfilled, for example “x<9999999″ or something like that. The structure of a recursive-function is exactly like any other functions, except with a little twist… instead of:

type name (parameters)
return ( [anything variable related] )


type name (parameters)
if-else loop with a condition to be fulfilled.
return ( [the function’s name and something modifying it] )


So let’s look at an example provided by CPlusPlus.com’s tutorial:

Pretty straight forward right? Each time the loop is called it is repeated and “a” is decreased until the condition is reached… Easy as pie.

Have fun and good luck!

28) Hard Workout – OVERLOAD

After a workout, you feel tired right? That’s because you pushed your body passed it’s usual limit by dumping for stuff to do it which is why your also hurt the next day. This concept is much like the “overload” concept used in the C++ language. Essentially, overloading is barraging one name/title with a lot of outcomes provided the conditions are met. If you didn’t understand what that means, let me break it down. A function’s title, is not unique to that function only, that title can be used with many other functions so long as the types of its parameters aren’t the same (at least on parameter has to have a different type). If you are unsure as to what a parameter is,  please refer back to post #25. So how do we control which function is used when we call upon the title you ask. Well the CPU isn’t a total dumdum, it knows that an “int” function can’t take “float” values, therefore it automatically searches for a function using:

  1. The title declared
  2. The type that is specified

Following the basic understanding of the capabilities of overload, let’s look at a basic application:

See how modify is called upon twice but each time a different function is used? That’s overloading in action, it can prove to be very helpful at times when you don’t want anything to go wrong so you include a bajillion functions each with a different type but the same statements. JOY!


Good luck and have fun!