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

  • SEARCH
  • Home
  • 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 8930771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:58:12+00:00 2026-06-15T08:58:12+00:00

I am currently browsing over some old college snippets of c++ code. Back then,

  • 0

I am currently browsing over some old college snippets of c++ code. Back then, one of the other class was assigned with doing a matrix class using double pointers and 2D arrays. Luckily (or unluckily upon hindsight) I never did get a chance to learn stuff like that. I borrowed their code when we graduated for future review. If anyone can please explain to me what exactly happens in this snippet:

  //This is a constructor of a 1x1 matrix
  signal::signal(){
     _nrows = 1;
     _ncols = 1;
     _coef = new double*[_nrows];
     _coef[0] = new double[_ncols];
     _coef[0][0] = 0.0;
  }

Just a sidenote, _coef is a ** of type double.

From what I understand, _nrows and _ncols are given a value of 1 (meaning their sizes). Then, the code dynamically creates a double* out in the heap with elements equal to _nrows; the problem is, I dont exactly know what happens next. Why is the array corresponding to _ncols not a pointer? Why is it assigned _coef[0]?

  • 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-06-15T08:58:13+00:00Added an answer on June 15, 2026 at 8:58 am

    In memory, a two dimensional array (n, m) looks more or less like this

    _coef -> | _coef[0] -> {1, 2, 3, ..., m}
             | _coef[1] -> {1, 2, 3, ..., m}
             | _coef[2] -> {1, 2, 3, ..., m}
             | ...
             | _coef[n] -> {1, 2, 3, ..., m}
    

    _coef points to an array of n pointers. And each of these pointers point to an array of m doubles.

    So, in your case _coef points to an array of 1 pointer and this pointer points to an array of one double.

    Now to your questions

    1. It is not a pointer, because in your second dimension, you finally want to store the doubles, not pointers.
    2. It is assigned to _coef[0], because it is the first, and only, row of your two dimensional array.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm starting a new Activity and calling finish on a current one. Is
Currently I have this code: <?php echo '<meta name=robots content=noindex>'; $arr = json_decode(file_get_contents(http://media1.clubpenguin.com/play/en/web_service/game_configs/ paper_items.json),true);
Hey guys, I've been browsing around on SO for quite some time and can't
I'm currently developping a database browsing app using Qt & C++. The databases are
I'm currently working with WatiN, and finding it to be a great web browsing
Currently, we're storing the user's HTTP_REFERER so we can redirect the user back to
We have an in-house code C++ COM library. We are currently consuming the library
I have the following code to display the currently logged in user in my
I am currently doing the following to generate a value at compile time, which
I was browsing through the code of Vosao CMS , an open source CMS

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.