7

Hello C++ / C programmers. I've noticed my professor putting the ASCII code of a character into an int instead of just using a char to store it. When he does this he's not doing math or anything with them, so is there any advantage to it? My TA mentioned something about memory alignment, but I'm not experienced enough to know how something being aligned differently in memory would help or hurt a program.

Comments
  • 0
    Is it some kind of micro device?
  • 0
    📌
  • 0
    I guess you can do maths with it, but no clue about this "Memory Aligment" thing.
  • 4
    It's a bad practice because an int has a weight of 4 bytes and a char has only one byte. Nowadays, it's not really problem but on embedded systems for example you shouldn't do something like this
  • 0
    In my (amateur student) opinion it doesn't make any sense. But it is hard to say without knowing the code. It would make more sense if he for example did math on it or maybe stored a pointer address instead of the value.
Add Comment