is memset() more efficient than for loop in C?

前端 未结 7 1394
不思量自难忘°
不思量自难忘° 2021-02-02 06:46

is memset more efficient than for loop. so if i have

char x[500];
memset(x,0,sizeof(x));

or

char x[500];
for(int i = 0 ; i &         


        
7条回答
  •  走了就别回头了
    2021-02-02 07:11

    Good compilers will recognize the for loop and replace it with either an optimal inline sequence or a call to memset. They will also replace memset with an optimal inline sequence when the buffer size is small.

    In practice, with an optimizing compiler the generated code (and therefore performance) will be identical.

提交回复
热议问题