Why is it that my first and second programs are running fine but the third one is giving segmentation fault? I don't think the problem is with memory limit because even long long dp[40][100000]
is running fine but if I try printing any value say std::cout << dp[0][0];
again it's giving error. I am really confused, I've tried compiling this code on Jdoodle and GDB online compiler. Both are giving the same error.
First:
#include<iostream>
#include<vector>
int main(){
std::vector<long long> price(20);
std::vector<long long> pages(20);
return 0;
}
Second:
#include<iostream>
#include<vector>
int main(){
long long dp[20][100000];
return 0;
}
Third:
#include<iostream>
#include<vector>
int main(){
std::vector<long long> price(20);
std::vector<long long> pages(20);
long long dp[20][100000];
return 0;
}
Edit: I am interested in knowing why the second program is running fine and the third is giving segmentation fault. I think either both or none of them should run without any errors.