Is this good-bye? Part 1

The semester is almost over!!!~~~ And summertime is coming! Whooo!!! So before we get into plans for the future, comp adventures and good-byes I want to update you w/ all I learned since my last post and before, lol. We take our last comp3010 class on Monday and then THE FINALS BEGIN!!!

Oh dear! So last time I posted something about what we learn in class here was about arrays!! That’s chapter 7!! Now we’ve covered all the way up to chapter 9. So we’ll have to go through what I didn’t discuss last time about chapter 7, those marvelous multidimensional arrays and chapters 8 and 9.

For lab 7 I had to do a two dimensional array and these videos are amazing! They tell you how to do it and how to print it out looking nice in a nutshell! Bucky is great! Check out his website while you’re at it!!

There’s a lot you can do with multidimensional arrays but they can get really complicated. Especially if you have deals, like me. Because for lab 7 I was trying to do a 3-dimensional array for this problem called LIFE and I was doing a double for and I was getting error messages and a lot of stress going on and then someone points out that duh! I need a triple for if I have 3D array. So you, know now I know that if it’s a 4D then I need 4 fors and so on!!!But the funny thing is that with a 1D you can do cool tricks w/ double fors like this that I did this morning:

Image

 

You see a 1D array with a double for. I also did that here:

Image

My point is, the amount of fors doesn’t neccesarily depend on the dimension but on what you wanna do with the array but you can only have more fors than the dimension not less ’cause if you have less you won’t be able to tell the program the exact positions in the array well unless you use a number on one of the brackets and then do the i’s and j’s on the others I guess…

So did I ever tell you guys that you cannot return an array? If you want a function that “returns” an array just use a void function and do a for to cout the thing right the thing. Array parameters are great because they change the array they are pointer parameters and kinda do what the call-by-reference parameters do.

Now let’s talk about what will happen if an index value that does not exist is entered. Well it will go to an address one of the things that could happen is that the memory location for that index already contained a variable and it overtakes the variable, changes the value and ruins everything. The worst thing that could happen is that there is no abort and your program continues with faulty data. The best thing that can happen is that the memory location is not part of our program and we get a segmentation fault. That one has happened to me, yep in one of the probs for lab 7. It happened twice. Luckily the mistakes were silly and I was able to spot them with the help of the prof and a friend just in time!

Segmentation fault means you are accessing (or trying to?) memory that is not allocated to your program.

There are two ways to initialize your array: sort hand notation a[number]={value} I guess this only works if you wanna initialize it to all with the same value. The other way is the long notation where you go like this:

a[0]=value;

a[1]=value;

a[…]=…;

The best way to initialize an array is using default values!! Like this one for the chars {”}.

Wherever you can use a variable you can also use an indexed variable. So we can use arrays as function arguments! You do the array parameter like this type name_of_func(type(of arr) arr[]) You NEVER use the size on a one dimensional array. But if it’s a 2D or any other #D different from one then you go like this, 4D for example: type name_of_func(type(of arr) arr[][10][9][4]). For some reason you don’t write the first size but you gotta write the rest. I think this has to do with the things the compiler needs to know about the program at compile time.

Then when you call the function you simply do this: name_of_func(arr) You do NOT use the brackets when doing the call. Got it? lol~

So what is really passed with an array parameter? The base address. Addresses are complicated things… For example the array a is a variable that holds an address and that address will be the address of a[0] then the next index has a different address which is the address of a[0] plus(+) something, an amount that has to do with the number of index but is not for example 1 if the index is one. It’s something related uh not sure what it was. Gotta ask the prof to repeat that for me because you know I have deals… He explained that in class but u know how it goes with me… I’m like the dumb one in class lol… 

So um you know how I said earlier that the value of the array changes as a result from what you do in the func? Because they’re similar to call-by-ref? Well if you don’t want that to happen just add const before the var type. Const only gives you read acces. Oooh!! That sounds like those annoying “read-only” files, gurrr.

So wow, I remember this one day the prof was talking about the right way to round something up but I’m not sure what this something was I’m pretty sure it had to do with arrays but anyway the right way to do this thing is like this:

static_cast<int>(floor(number+0.5));

Now let’s take a break from class to complain and adventure! Complain: My back hurts like hell, ouch!!! WOOO 😦 Don’t know why??? 😥

Adventures:

I wanna thank all these people who recently became my followers! Yay! 

Image

Image

Image

Anyway this is it for today I’ll write more tomorrow I’m ultra tired! Thanks everyone!!!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s