Is the "const" specifier necessary? Any benefit?

#include <iostream>
using namespace std;

void printBinary(const unsigned char val) {
for(int i = 7; i >= 0; i--)
if(val&(1 << i))
cout << "1";
else
cout << "0";
}

I tried calling the above function without "const" specifier, and it still works.

Any potential risk without the "const"?
Not really. In this case all it means it that val cannot be changed in the printBinary function. It might allow for some minor compiler optimizations, but it likely won't make any difference.
Thanks for your elaboration, which is helpful. I appreciate it.
Topic archived. No new replies allowed.