Search:
Forum
General C++ Programming
What is the difference between the follo
What is the difference between the following two code segments?
Jan 6, 2020 at 2:17am UTC
shanno8
(6)
// code segment 1
int i = 48;
char ch = i;
// code segment 2
int i = 48;
char ch = static_cast<char>(i);
Jan 6, 2020 at 2:30am UTC
Ganado
(6811)
First code converts the int to a char.
Second code casts int to a char. Think of a static_cast as being a more explicit conversion; sometimes it's necessary or the code won't compile (e.g. for enum classes).
In this case, the result is the same.
Last edited on
Jan 6, 2020 at 2:36am UTC
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs