Ive got two questions about learning c++

so I started watching tutorials from a guy on youtube named "bucky", Ive come to the part 35 at this point, out of 70, but its from 2011, should I continue or find some other tutorials I can follow, because 2011 was long ago, and also Ive got myself a code I cannot make to work, even tho its simple so if you could check it out, when I do it with the old kind of array it works but with this way its not working and I cannot figure it out even tho it seems the problem is very obvious.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include "pch.h"
#include <iostream>
#include <array>
using namespace std;

void printarray(int thearray[], int sizeofarray);
	

int main()
{
 

	array<int, 3>jeff{ 3,6,11 };


	printarray(jeff, 3);
	

	
}

void printarray(int thearray[], int sizeofarray){

	for (int x = 0; x < sizeofarray; x++) {

		cout <<   thearray[x] << endl;
	}
}
His tutorials do have some outdated information, but for the most part, they are VERY useful.

So for the first part, your function prototype,

void printarray(int thearray[], int sizeofarray);

Should look like this:

void printArray(int [], int );

You have variables that are not defined in your prototype, thus the computer doesn't know what to do. Also, CamelCase your identifiers.

I've attached an example of a function call with an array. Maybe it can help you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

const int COLS = 4;
const int ROWS = 3;
void myArray(const int[][COLS], int);

int main()
{
	int nums[ROWS][COLS] = {{ 1,2,3,4 }, {6, 7, 8, 9}, { 9,10,11,12 }};

	myArray(nums, ROWS);

	return 0;
}

void myArray(const int num[][COLS], int row)
{
	for (int i = 0; i < row; i++)
		for (int j = 0; j < COLS; j++)
			cout << num[i][j] << " ";
}


Here is what the program should look like though in case you are still confused.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

void printArray(int [], int); // function prototype

int main()
{
	int jeff[3] = { 3,6,11 }; // You don't need #include <array>, we can define an array as such.

	printArray(jeff, 3); // function call with jeff and 3 as arguements, based off of prototype.

	return 0;
}

void printArray(int theArray[], int sizeOfArray) { // function header

	for (int x = 0; x < sizeOfArray; x++) {

		cout << theArray[x] << endl;
	}
}
Last edited on
I will keep watching his stuff then, and also thank you a lot for responding in such details.
Inspireftw wrote:
So for the first part, your function prototype,

void printarray(int thearray[], int sizeofarray);

Should look like this:

void printArray(int [], int );


This is nonsense. It's fine to name the arguments in the prototype. In fact, it's a good idea to do so, because it makes it clear what those arguments are for.
Last edited on
Topic archived. No new replies allowed.