Passing arguments to functions with const parameters: is it faster?

前端 未结 4 738
盖世英雄少女心
盖世英雄少女心 2021-02-07 00:32

Consider, for example:

int sum(int a, int b)
{
    return a + b;
}

vs.

int sum(const int a, const int b)
{
    return a + b;
}
         


        
4条回答
  •  萌比男神i
    2021-02-07 00:49

    The answer probably depends on your compiler, the optimization level, and whether the compiler decides to inline the function. If you are curious about these things, it is easy to just look at the actual assembly produced by your compiler and find out.

提交回复
热议问题