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 6605485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:17:22+00:00 2026-05-25T19:17:22+00:00

The objective here is to have a pointer that works like a 2D matrix.

  • 0

The objective here is to have a pointer that works like a 2D matrix. I’ve tested the following bit of code for creating a pointer to and array of integer pointers. It compiles and runs fine. (This is a simplified version, I’ve tried assigning/printing values to mymatrix[x][y] and it works fine.)

#include <iostream>
int **mymatrix;

int main(int argc, char* args[]){

  mymatrix = new  int*[100] ;
  for( int n = 0; n <= 100; n++ ){
    mymatrix[n] = new int[200] ;
  }
  return 0;
}

However, as soon as I copy this snippet to another code (which previously ran fine), the code still compiles but fails to run. There are no errors or warnings related to this snippet. This is weird because mymatrix doesn’t even interact with the rest of the code yet (after being defined it’s just never used again).

The actual error which interrupts the execution varies between crashing when trying to load a font, Segmentation Fault when trying to assign a value, and Memory Corruption (with a huge log output of what I think are threads).

I could paste sections of the larger code, but I’m almost convinced that this is all happening because I’m not defining this pointer in the proper way. Am I doing something clumsy or unsafe here? Or should I start looking through the rest of my code for bugs?

  • 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-25T19:17:23+00:00Added an answer on May 25, 2026 at 7:17 pm
    for( int n = 0; n <= 100; n++ )
    

    This causes an array overrun. mymatrix[100] is not part of the mymatrix array. The result of writing to it is undefined. The reason it “works fine” by itself is that there aren’t other data structures for you to clobber. The for loop should start with.

    for( int n = 0; n < 100; n++ )
    

    In general the use of <= in for loop conditions is not idiomatic c. If you find yourself using it, you should ask yourself if you are really doing the right thing. Array overruns are sometimes hard to find. If you are on linux, you can use a tool like valgrind to help you identify this and other errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an anonymous struct in my code that I'd like to access via
I have a pointer in an objective-C class that I need to send messages
REAL newbie here to Objective C and Cocoa. I have this 'if statement' if
Objective: In support of a Windows Service that may have multiple instances on a
I'm using cocos2d with objective C. I have a class called CrystalineBubble that is
Here's the scenario: I have a program that contains an annotation that I built
I have the following code in my iPhone app CGPoint p = [StaticClass doSomethingWithA:a
I have a C struct that contains a function pointer. Now, I have used
Let's say I have a generic pointer in objective-c. This pointer could either be
I have the following code to count and trigger some functions using jQuery: jQuery('#input_guideName').keyup(function(e)

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.