May 19, 2013, 01:06:07 PM
 News: Welcome!
 Forum Home Help Search Forum Login Register
Pages: [1]   Go Down
 Send this topic  |  Print
 Author Topic: void, int, and arrays  (Read 279 times)
joey201
Newbie

Posts: 1

 « on: June 25, 2012, 01:42:49 PM »

Hello all thank you for the work done in the tutorials I'm following them and really enjoying them got to up to the tic tac toe part. Anyways I got a question I noticed in the first few lessons we used int to declare/initialize/call (I get confused with those words) main function but as I moved along I noticed that now I'm using void main (){ ...

So my question is what is the diference between void and main in the main function call.

Another question I got is about arrays. I understand how they are declared and the several ways to initialize them, what confuses me is when I can't do

Code:
iaArray1 = iaArray2;

Code:
int iaArray1[3] = {1,2,3};
int iaArray2[3];
int iIndex = 0;
while (iIndex < 0) {
iaArray2[iIndex] = iaArray1[iIndex];
}

could I have done this:

Code:
int iaArray1[3] = {1,2,3};
int iaArray2[3];
int iIndex = iaArray1;
int iaArray2 = iIndex;
}

What I understand is the first one is not possible the second one iaArray1 equals iaArray2 as long as iIndex is less than 0. In the third one (the one I made up) its saying iIndex equals iaArray1 and iaArray2 equals iIndex.

Anyway if anyone could develop a bit more I will greatly appreciate it.

 « Last Edit: June 25, 2012, 02:17:20 PM by joey201 » Logged
Michael Hall
Hero Member

Posts: 899

 « Reply #1 on: June 25, 2012, 03:10:17 PM »

I would use the "int" as a return type. "void" only works in Microsoft. That's why I switched to using "int" when I updated the videos. The later ones all use "int."

The first one is a pointer assignment. This is a pointer address assignment.

The second one is almost right. To copy an array, you need to copy each entry. However, this loop lack any method of incrementing or decrementing the index. Something more this would work:

Code:
for (int iIndex = 0; iIndex < 3; ++iIndex) {
iaArray2[iIndex] = iaArray1[iIndex];
}

The third example switches the type back and forth. This ends up being roughly the equivalent of the first one.

Mike
 Logged
Pages: [1]   Go Up
 Send this topic  |  Print