recently, I have learnt about C++. Specially, I learned about memset function. But I don't know how to set value for 2d array at specific row
Example:
int dp[10][10];
// I want to set all values for dp[0] by using memset
// I can do it, by using For loop, like
for (int i = 0; i < 10; i++)
dp[0][i] = 1000;
I have tried this
memset(dp[0], 1000, sizeof dp[0]);
But it's not working well.
So I want to know if there are any ways to use memset like what I hope? Thanks :D
memsetfor that? With optimizations enabled, compilers will turn the loop andmemsetinto the same assembly. You could also usestd::array< std::array<int, 10>, 10>instead of a C array to make it easier.memset(), to address bigger chunks than single bytes values. What you have there is already the fastest possible way to initialize that array with some value different from0.