When looking over some code from a friend's project, I recently saw syntax that looked like this.
#include <iostream>
int main(){
std::cout<< int(32.5/5) << std::endl;
}
When you run the above code, you get 6
, which is the expected value if the use of int
functions like a cast.
However, I have never seen this syntax before and I could not find documentation for it on the web. I also did an experiment and noticed that this syntax is not valid in C
.
Can someone explain the meaning of this syntax with documentation references?
This is not a constructor call or a "function". There is no "int function".
This is functional cast notation; it's just a cast.
It's the same as (int)(32.5/5)
(in this particular case).
And, no, C does not have it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With