Debugging Code in Dev-C++: Solving an Unexpected Disappearance

  • Context: C/C++ 
  • Thread starter Thread starter FrostScYthe
  • Start date Start date
  • Tags Tags
    Code Debugging
Click For Summary
SUMMARY

The discussion centers on a coding issue encountered in Dev-C++ where an undefined variable 'n' causes the program to terminate unexpectedly. The user initially attempts to allocate memory for arrays 'a' and 'b' without initializing 'n', leading to undefined behavior. Upon realizing the need to initialize 'n', the user confirms that the program runs correctly when 'm' is omitted, indicating that the problem was due to the uninitialized variable rather than the presence of 'm'. This highlights the importance of variable initialization in C++ programming.

PREREQUISITES
  • Understanding of C++ memory management and dynamic allocation
  • Familiarity with pointers and arrays in C++
  • Knowledge of the Dev-C++ IDE and its debugging features
  • Basic concepts of variable initialization and scope in C++
NEXT STEPS
  • Research C++ dynamic memory allocation techniques using 'new' and 'delete'
  • Learn about debugging tools in Dev-C++ to identify runtime errors
  • Study the implications of uninitialized variables in C++ programming
  • Explore best practices for managing memory in C++ applications
USEFUL FOR

This discussion is beneficial for C++ developers, students learning programming, and anyone troubleshooting memory-related issues in their code using Dev-C++.

FrostScYthe
Messages
80
Reaction score
0
Ok, I'm trying this code in Dev-C++

int main(int argc, char **argv)
{
double **a;
double *b;
// double *m;
int n, iter;
double tol;

b = new double[n];

a = new double*[n];
for (int i = 0; i < n + 1; i++)
a = new double[n];

// m = new double[n];

count << "I'm ready to continue =)!";

system("PAUSE");
return 0;
}

If I omit the m vector, the program will run and not disappear in a second and it will be ready to continue.. but when I declare the m vector without even doing anything with it... it just runs and quits quicker than I can blink my eye...! Why is this happening =(?
 
Technology news on Phys.org
Forget this post, I just realized I had to initialize n before doing any of this ... tehe =)
 
n is undefined.

Edit: Sorry, just saw your follow up.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 30 ·
2
Replies
30
Views
5K