Reset C int array to zero : the fastest way?

前端 未结 7 1294
感情败类
感情败类 2020-12-22 18:34

Assuming that we have a T myarray[100] with T = int, unsigned int, long long int or unsigned long long int, what is the fastest way to reset all its content to

7条回答
  •  时光说笑
    2020-12-22 19:04

    From memset():

    memset(myarray, 0, sizeof(myarray));
    

    You can use sizeof(myarray) if the size of myarray is known at compile-time. Otherwise, if you are using a dynamically-sized array, such as obtained via malloc or new, you will need to keep track of the length.

提交回复
热议问题