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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:45:03+00:00 2026-06-14T18:45:03+00:00

Possible Duplicate: Max Array Size in C My question is: Does Code::blocks have a

  • 0

Possible Duplicate:
Max Array Size in C

My question is: Does Code::blocks have a max number of iterations for a loop?

I am running a monte carlo and I would like to run a million particles through a for loop. But the max it seems to go without crashing is 110000.

Thanks!

Some more info:

I am using a random number generator seeded by time:

    srand(time(NULL));

I then want to create a million particles (random)

    for(k=0; k<M; k++){
    R[k] = rand()*(1)/(double)RAND_MAX;
    z[k] = -log(1 - R[k])/(1000*U);

where M = Num/10 (I want to #define N 1000000)

This is the only thing I can think of that is creating the problem?

Here is an example code that will not work.

    #include <stdio.h>
    #include <math.h>
    #include <time.h>
    #include <stdlib.h>

    int main(){

      srand(time(NULL));

       int j=0;
       int i;
       double A[1000000];

       for(i=0;i<1000000;i++){
          A[i] = rand()*(1.0)/(double)RAND_MAX;
           if (A[i] == 1.0){
              printf("Wow!\n");
           }
       }

       return 0;

    }

Could this be due to my settings of Code::blocks by any chance?

  • 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-14T18:45:05+00:00Added an answer on June 14, 2026 at 6:45 pm

    Edit: this is because the default maximum stack size is 1MB on Windows (but 8MB on Linux).

    I don’t have a final answer, but I do know:

    a) It runs fine from a Linux command-line.

    b) Valgrind gives tons of errors of this form:

    ==2465== Invalid write of size 8
    ==2465==    at 0x804851D: main (test2.c:16)
    ==2465==  Address 0xbe4480e4 is on thread 1's stack
    ==2465== 
    ==2465== Invalid write of size 4
    ==2465==    at 0x8048521: main (test2.c:16)
    ==2465==  Address 0xbe4480e0 is on thread 1's stack
    ==2465== 
    ==2465== Invalid read of size 4
    ==2465==    at 0x4081D69: printf (printf.c:35)
    ==2465==    by 0x8048528: main (test2.c:16)
    ==2465==  Address 0xbe4480e0 is on thread 1's stack
    ==2465== 
    ==2465== Invalid read of size 8
    ==2465==    at 0x407AC05: vfprintf (vfprintf.c:1622)
    ==2465==    by 0x4081D7F: printf (printf.c:35)
    ==2465==    by 0x8048528: main (test2.c:16)
    ==2465==  Address 0xbe4480e4 is on thread 1's stack
    

    c) The errors are clearly related to reading and writing from the array. This simpler version of the program does not cause any Valgrind errors:

    #include <stdio.h>
    #include <math.h>
    #include <time.h>
    #include <stdlib.h>
    
    int main(){
      srand(time(NULL));
      int i;
      for(i=0;i<1000000;i++){
         if (rand()*(1.0)/(double)RAND_MAX == 1.0){
             printf("Wow!\n");
         }
      }
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Android: Set interval in SeekBar I have a seekbar with max value
Possible Duplicate: Extracting indices for data frame rows that have MAX value for named
Possible Duplicate: Max file number can php upload at same time I'm trying to
Possible Duplicate: Find the min number in all contiguous subarrays of size l of
Possible Duplicate: What is JavaScript's Max Int? What's the highest Integer value a Number
Possible Duplicate: What is JavaScript's Max Int? What's the highest Integer value a Number
Possible Duplicate: python max of list of arrays I have a list of arrays
Possible Duplicate: min and max in multidimensional-array How do i find max and min
Possible Duplicate: Finding the max repeated element in an array If there is a
Possible Duplicate: Min Max slider to form I presently have a search module that

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.