In addition to dbush's answer, although there likely wouldn't be a problem on most modern systems using memset, the memset version (as written) is more brittle. If someday you decided to change the size of myArray, then one of two things would happen with the version using the braced initializer list:
- If you decreased the size of
myArray, you will get a compilation error about having too many initializers.
- If you increased the size of
myArray, any elements without an explicit initializer will automatically be initialized to 0.
In contrast, with the memset version:
- If you decreased the size of
myArray without remembering to make a corresponding change to memset, memset will write beyond the bounds of the array, which is undefined behavior.
- If you increased the size of
myArray without remembering to make a corresponding change to memset, elements at the end will be uninitialized garbage.
(A better way to use memset would be to do memset(myArray, 0, sizeof myArray).)
Finally, IMO using memset in the first place is more error-prone since it's quite easy to mix up the order of the arguments.