Would I be correct by saying that enum by default is not very memory friendly approach? What if each element of enum can only ever be initialized up to 255. Instead of assigning a single byte per each entry now we have 4 bytes allocated?
So I've never thought of that before, but I suppose that's true in the sense that a char could be used in that case. Because an enum is guaranteed to be able to store what int can store, which means it's going to be 4 bytes in practice on most systems/compilers, though it could technically possibly be more: stackoverflow.com/a/366026. If you were using A LOT of enums, like very, very massive arrays of enum type values, this distinction might become important if we could get away with just using char type instead or something else. Otherwise I don't think it would matter much in practice, but it's a good interesting question to think about. :-)
So notice that when you change the value of Tuesday to 9. However, when you recompiled, your value for Wednesday changed to 10; What caused that to happen?
It's essentially just "the way C works" that if we assign an integer to an enum value, then the next enum value will take on the next integer. So there isn't really a deeper reason than that. :-)
Kevin great video! On Linux I found after assigning a value to a single element it changed all the elements around it ie. If Thursday is given the integer value 10 then by default Wednesday becomes 9 and Friday becomes 11. Wether this is the same on other compilers I have no idea but something to look out for.
2:33 when tuesday = 9, wednesday value automatically gettiing changed to 10 in the output. but specifically given value like friday = 20 doesn't change.
@@Vishwa2757 Thank you! your right, and I must have missed it watching the video. Doing an experiment assigning Wednesday = 9 and Saturday = 22 I got the following output 0, 1, (9), 10, 11, (22), 23 indicating only subsequent numbers to those defined are affected.
God day, Sir. As I can see you use a mouse in the video, but at the same time you jump from one line to another in a split second. Question. Do you use some shortcuts or another auxiliary application? I have noticed, I spend a lot of time to reach my mouse and it is annoying =)
Good question! :-) I don't do anything too fancy... just moving the cursor really fast with the keyboard up/down keys, and I copy, cut and paste with keyboard shortcuts as well (Command-C, Command-X and Command-V on Mac, or Ctrl-C, Ctrl-X and Ctrl-V on Windows). A lot of developers try to use the mouse as little as possible because it's considered slower to switch between mouse and keyboard. I'm not that strict about it myself but I like to use shortcut keys when I can.
@7:35 it is amazing how software and hardware can talk to each others - I love those things - Thanks Kevin.
Agreed, and you're welcome! :-)
Would I be correct by saying that enum by default is not very memory friendly approach? What if each element of enum can only ever be initialized up to 255. Instead of assigning a single byte per each entry now we have 4 bytes allocated?
So I've never thought of that before, but I suppose that's true in the sense that a char could be used in that case. Because an enum is guaranteed to be able to store what int can store, which means it's going to be 4 bytes in practice on most systems/compilers, though it could technically possibly be more: stackoverflow.com/a/366026. If you were using A LOT of enums, like very, very massive arrays of enum type values, this distinction might become important if we could get away with just using char type instead or something else. Otherwise I don't think it would matter much in practice, but it's a good interesting question to think about. :-)
So notice that when you change the value of Tuesday to 9. However, when you recompiled, your value for Wednesday changed to 10; What caused that to happen?
It's essentially just "the way C works" that if we assign an integer to an enum value, then the next enum value will take on the next integer. So there isn't really a deeper reason than that. :-)
Great vid
Thank you Ramen, I’m glad you enjoyed it! :-)
Kevin great video! On Linux I found after assigning a value to a single element it changed all the elements around it ie. If Thursday is given the integer value 10 then by default Wednesday becomes 9 and Friday becomes 11. Wether this is the same on other compilers I have no idea but something to look out for.
That's interesting thanks for sharing that Peter! :-)
2:33 when tuesday = 9, wednesday value automatically gettiing changed to 10 in the output.
but specifically given value like friday = 20 doesn't change.
@@Vishwa2757 Thank you! your right, and I must have missed it watching the video. Doing an experiment assigning Wednesday = 9 and Saturday = 22 I got the following output 0, 1, (9), 10, 11, (22), 23 indicating only subsequent numbers to those defined are affected.
@@Vishwa2757 Thank you for that clarification! 🙂
God day, Sir.
As I can see you use a mouse in the video, but at the same time you jump from one line to another in a split second.
Question.
Do you use some shortcuts or another auxiliary application? I have noticed, I spend a lot of time to reach my mouse and it is annoying =)
Good question! :-) I don't do anything too fancy... just moving the cursor really fast with the keyboard up/down keys, and I copy, cut and paste with keyboard shortcuts as well (Command-C, Command-X and Command-V on Mac, or Ctrl-C, Ctrl-X and Ctrl-V on Windows). A lot of developers try to use the mouse as little as possible because it's considered slower to switch between mouse and keyboard. I'm not that strict about it myself but I like to use shortcut keys when I can.
Nice 🙃.
I’m glad you enjoyed it! :-)
thanks. :)
You're welcome! :-)