Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3616984
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:33:58+00:00 2026-05-18T22:33:58+00:00

Edit: I’ve completely revised my question as I have a better idea of what

  • 0

Edit:

I’ve completely revised my question as I have a better idea of what I want to do.

#include <iostream>
#include <cstdlib>
using namespace std; 

int main(){
    const int max_rows = 10; 
    const int max_cols = 10; 

    int *test = new int[max_rows * max_cols]; 

    for(int i = 0; i < 100; i++){
        test[i] = 1 + (rand() % 100);  
    }

    for(int i = 0; i < 100; i++){
        cout << "#" << i << " " << test[i] << endl; 
    }

    int *b = &test[0]; 

    cout << *b << endl; 

    int *x = b + (i * sizeof(int) * max_cols) + (sizeof(int) * j); 

    cout << *x << endl; 

    return 0; 

}

test is supposed to be my two-dimensional array.

*x is supposed to contain the address of test[i][j]
(assume that I have the cin >> i and cin >> j in my code).

where i is the row and j is the column that I want.

But it doesn’t seem to be giving me the correct address. Unless I’m silly and reading it wrong.

This is the way that I was told to do the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:33:59+00:00Added an answer on May 18, 2026 at 10:33 pm

    Of course there is simple way, you need allocate one-dimensional array but use it as 2 dimensional:

    const int row = 5;
    const int col = 7;
    int *twoD  = new int[row * col];
    std::cout << twoD [4*row + 3]; //sample to access [3][4]
    return 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit (updated question) I have a simple C program: // it is not important
EDIT: Simple version of the question: I want to create server variables in the
EDIT: I have reworded the title question slightly, and adjusted the text to respond
EDIT: I rephrased the question because I have not explained well. Let's see if
Edit: The below question was answered by this . I have a new updated
EDIT: I'm using MySQL, I found another post with the same question, but it's
EDIT: If the question is badly written have a look at the video (
Edit Using the answers to the question I changed the test to the following
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: See my answer below--> I am wanting to have a view that when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.