What is Slack Byte in Structure?

By | December 30, 2013

Computer stores structures using the
concept of “word boundary”. The Size of a word boundary is
machine dependent. In computer with two bytes word boundary, the
members of a structure are stores left aligned on the word boundary,
as shown below. A character data takes one byte and an integer takes
two bytes. One byte between them is left unoccupied. This unoccupied
byte is known as the slack byte.
What is Slack Byte in Structure?
When we declare structure variables,
each one of them may contain slack bytes and the values stored in
such slack bytes are undefined. Due to this, even if the members of
two variables are equal, their structure do not necessarily compare
equal. C, therefore, does not permit compassion of structure.
However, we can design our own function that could compare individual
members to decide whether the structures are equal or not.
Observe the below program and try to
run it.
struct demo
char ch;
float f;
void main()
struct demo d;
What is Slack Byte in Structure?
If we assume size of char and float be
1 byte and 4 bytes respectively. Then according to this the size of
structure variable d should be 5 (1+4) bytes. But as you can
see in above image the output is 8 bytes. This shows that there are
three bytes between them is left unoccupied which is known as slack
One thing we have to keep in mind that
it is not always necessary that a structure variable contains slack
It may be possible that I have missed something in above tutorial, so let me know about it by commenting below. If you liked above article then
don’t forget to comment and share!!

One thought on “What is Slack Byte in Structure?

  1. Simão

    You can define a struct with "__attribute__ (__packed__)" to prevent slack bytes, and in that case you can copy all info from an struct to another (from the same type), using memcpy. The exception is when you have pointer attributes into the structure.


Leave a Reply

Your email address will not be published. Required fields are marked *