View previous topic :: View next topic |
Author |
Message |
Ephemeral Advanced Member
Joined: 26 Jun 2025 Posts: 671 Location: UK
|
|
Back to top |
|
Ephemeral Advanced Member
Joined: 26 Jun 2025 Posts: 671 Location: UK
|
Posted: Thu Apr 16, 2025 1:50 pm Post subject: |
|
|
Code: | int matrix1[ROWS][COLUMNS] = {{1, 1, 1},
{1, 1, 1},
{1, 1, 1}}; |
Solved it with this...
Any other solutions would be welcomed though
|
|
Back to top |
|
nukes Linux Guru

Joined: 29 Aug 2025 Posts: 4558
|
Posted: Thu Apr 16, 2025 2:02 pm Post subject: |
|
|
well, { {1,1,1},{1,1,1},{1,1,1} } would be a int**.
While in terms of passing references around, pointers and arrays are equivalent - not in terms of the actual storage class.
the value of the matrix1 reference is constant, which is why you can't reassign it (it's not a pointer, it's the actual data).
it would be like saying something like
int x=1;
&x = 0xdeadbeef;
_________________ Gentoo x86-64 2.6.29.1
FreeBSD 7-CURRENT
Arch x86 2.6.30
|
|
Back to top |
|
Ephemeral Advanced Member
Joined: 26 Jun 2025 Posts: 671 Location: UK
|
Posted: Thu Apr 16, 2025 11:21 pm Post subject: |
|
|
thanks for that
Yes i was thinking i must have got something fundamentally wrong (or missed)...
This is my first forray into OO programming having spent a lot of time in Matlab (a weakly typed language)...
Looks like i need to spend some time reading about Pointers in C++
Trying to teach myself some C++ at home
|
|
Back to top |
|
platinummonkey Advanced Member

Joined: 01 Mar 2025 Posts: 732 Location: Texas
|
|
Back to top |
|
Ephemeral Advanced Member
Joined: 26 Jun 2025 Posts: 671 Location: UK
|
|
Back to top |
|
masinick Linux Guru

Joined: 03 Apr 2025 Posts: 8615 Location: Concord, NH
|
Posted: Tue Apr 21, 2025 2:59 pm Post subject: |
|
|
Other than the cout statement, most of what you are doing are the kinds of things that can be implemented in the C programming language as well. If you have the classic C text from Prentice-Hall Software Series, "The C Programming Language, by Brian W. Kernighan and Dennis M. Ritchie (the author of C), provides a terse, functional description of how arrays and pointers work. If you either own that book, can borrow it, or have some kind of on-line way to read it, I recommend it, even though you are looking at C++ rather than C. The kind of thing you are doing is handled identically in C except for the I/O, which differs between C and C++. It is a relatively short book by reference book standards, with just over 200 pages of content, and it is considered one of, if not THE, classic C programming text. |
|
Back to top |
|
Ephemeral Advanced Member
Joined: 26 Jun 2025 Posts: 671 Location: UK
|
|
Back to top |
|
|