Memory Consumption in long long vs int?

If I declare 2 global variables
int a[10000][10000] and long long b[10000][10000], will the both occupy same amount of memory initially? and after filling same values in both a and b will the amount of memory used by both be equal?

No don’t declare 2d array of long long , it will give u memory limit exceed.

1 Like

does it use more memory that 2d int array ??

Yes obviously , size of long long int is 8 bytes, int has 4 byte.

4 Likes
[simon@simon-laptop][15:53:10]
[~/devel/hackerrank/otherpeoples]>cat blah23.cpp 
#include <iostream>
using namespace std;

int a[10000][10000];
long long b[10000][10000];

int main() 
{
    cout << "sizeof a: " << sizeof(a) << endl;
    cout << "sizeof b: " << sizeof(b) << endl;
}
[simon@simon-laptop][15:53:14]
[~/devel/hackerrank/otherpeoples]>g++ blah23.cpp -O3 -g3 -Wall -Wextra
[simon@simon-laptop][15:53:31]
[~/devel/hackerrank/otherpeoples]>./a.out 
sizeof a: 400000000
sizeof b: 800000000
3 Likes

Ohh Right! Thank you

Got It! Thanks…btw nice representation.

2 Likes

almost one week before I was trying some A question on CF and I take long long 2d array , and it give me memory limit exceed , I m like WTH how memory limit exceed then I get to know this .

2 Likes