Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ function argument, int short

Tags:

c++

When I only use short integers in my program, is it better to use:

void printVars(int x1, int x2, int x3)

or

void printVars(short int x1, short int x2, short int x3)

as argument for my functions?

Thank you in advance.

like image 758
Pietair Avatar asked Apr 08 '26 16:04

Pietair


1 Answers

If you are 100% sure you will never use bigger integers than short int, it's better to use it as it might save 2 bytes (in most of the cases, on most systems, but not necessarily). It's indeed always a good idea to not use more resources than you need. The difference would probably be negligible with most applications though.

like image 184
Laurent S. Avatar answered Apr 10 '26 04:04

Laurent S.