10 ms·
C++ Solution for Hackerrank Encryption Challenge – Hazem Saleh – Medium
- jaytaylor 8y agoThis code did not compile using g++ 4.8.4. g++ -o hazem_saleh_suckarank hazem_saleh_suckarank.cc hazem_saleh_suckarank.cc: In function ‘std::string encryption(std::string&)’: hazem_saleh_suckarank.cc:20:43: error: variable-sized object ‘grid’ may not be initialized char grid[lowerbound][upperbound] = {0}; ^ Fixed by: - remove: " = {0}" from line 20 - insert after line 20: memset(grid, 0, lowerbound*upperbound * sizeof(char)); Question: Am I missing a flag or other compiler setting? I was able to fix the issue by zeroing with memset. However, cppreference.com [0] states that post-C99 "some-array-declaration-here = {0}" will zero out the structure. [0] http://en.cppreference.com/w/c/language/array_initialization http://en.cppreference.com/w/c/language/array_initialization
- akx 8y agoCompile with `-std=c++11`, maybe?