•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,577 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,634 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1692 | Replies: 6 | Solved
![]() |
hey there. my problem is pretty simple (i think). I dont know how to point at a multi dimensional array.how i understand normal array pointers is:
right. thats fine. in my mind thats how it works and it makes me happy. like I said, im a newb. So if i totally misunderstand the workings of pointers please enlighten me. BUT now if i say:
i get an error that tells me:
"cannot convert `std::string (*)[2]' to `std::string*' in initialization "
so what must i do???
the reason why i want to point to multi-dimensional arrays is basically because i have a [4][4] grid of type string that displays tiles in a 10x10 grid on-screen, like so:
####
#### y
####
####
x
I want to add another type of char to a specific coordinate on THAT SPECIFIC grid, using a function, which is why I am using pointers.
####
#### y
##@#
####
x
but i get an error message
. hope that explanation helps
thanks
C++ Syntax (Toggle Plain Text)
int numbers[5]; int *p = numbers; //so now *p points to numbers[0] //so if you say: *p = 10; //is the same as saying numbers[0] = 10; //now by saying: p++; *p = 20; //you are basically saying numbers[1] = 20;
right. thats fine. in my mind thats how it works and it makes me happy. like I said, im a newb. So if i totally misunderstand the workings of pointers please enlighten me. BUT now if i say:
C++ Syntax (Toggle Plain Text)
int numbers[4][2]; int *p = numbers;
i get an error that tells me:
"cannot convert `std::string (*)[2]' to `std::string*' in initialization "
so what must i do???
the reason why i want to point to multi-dimensional arrays is basically because i have a [4][4] grid of type string that displays tiles in a 10x10 grid on-screen, like so:
####
#### y
####
####
x
I want to add another type of char to a specific coordinate on THAT SPECIFIC grid, using a function, which is why I am using pointers.
####
#### y
##@#
####
x
but i get an error message
. hope that explanation helpsthanks
=======================
I CANT GET AN IMAGE IN MY SIG :(
=======================
I CANT GET AN IMAGE IN MY SIG :(
=======================
Examples
c++ Syntax (Toggle Plain Text)
int numbers[4][2]; int (*p)[2] = numbers; (*p)[0] = 0; // numbers[0][0] = 0; p++; // move to next row (*p)[0] = 0; // numbers[1][0] = 0;
hmm... just one more thing, if
refers to numbers[1][0]
then how do you refer to numbers[0][3] for instance? like not the first [], but the second []?
C++ Syntax (Toggle Plain Text)
(*p)[0] = 0; // numbers[1][0] = 0;
then how do you refer to numbers[0][3] for instance? like not the first [], but the second []?
=======================
I CANT GET AN IMAGE IN MY SIG :(
=======================
I CANT GET AN IMAGE IN MY SIG :(
=======================
Take a look at this:
cpp Syntax (Toggle Plain Text)
int main() { int numbers[4][4] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 0, 9, 8, 7 }, { 6, 5, 4, 3 } }; int (*p)[4] = numbers; (*p)[0] = 42; p++; (*p)[3] = 63; for ( int y=0, x; y<4; y++ ) { for ( x=0; x<4; x++ ) std::cout<< numbers[y][x] << " "; std::cout<< "\n"; } return 0; }
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- C++ Multi dimensional arrays (C++)
- Creating a multi-dimensional Session variable (PHP)
- Passing multi-dimensional array (C)
- Multi-dimensional Arrays: (Python)
- Help: Passing arrays between functions (C)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- How to implement multi-dimensional arrays in Python?? (Python)
- Need help passing a multi-dimensional array (C++)
Other Threads in the C++ Forum
- Previous Thread: c++ cashier
- Next Thread: Two Player Craps



Linear Mode