memory allocation run time error

Program crashes after taking 'test' input. This is just a snippet of code. I don't understand why.

1
2
3
4
5
6
7
8
9
10
11
12
13
using namespace std;  
#define SIZE 2000000000002
int main()
{

    unsigned long long int *t;
    t = (unsigned long long int*) calloc (SIZE,sizeof(unsigned long long int));
   
    unsigned long long int test;
  
    cin >> test;
    t[1]=192
}
Line 8: You don't check if the calloc was successful. You're asking for 2 16 TB of memory. Unlikely your OS is going to give you that much memory, even on a 64 bit machine. Since the call is likely failing, any reference to *t (line 12) is invalid.

Edit: Correct memory requested. Thanks Chervil.
Last edited on
Sixteen terabytes? (assuming 8 bytes for each unsigned long long int).
Topic archived. No new replies allowed.