In C++, is (int) ch equivalent to int(ch).
If not, what’s the difference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are the same thing, and also the same as
(int)(ch). In C++, it’s generally preferred to use a named cast to clarify your intentions:static_castto cast between primitive types of different sizes or signednesses, e.g.static_cast<char>(anInteger).dynamic_castto downcast a base class to a derived class (polymorphic types only), e.g.dynamic_cast<Derived *>(aBasePtr).reinterpret_castto cast between pointers of different types or between a pointer and an integer, e.g.reinterpret_cast<uintptr_t>(somePtr).const_castto remove theconstorvolatilequalifiers from variables (VERY DANGEROUS), e.g.const_cast<char *>(aConstantPointer).