Thread: sizeof struct

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    1

    sizeof struct

    Hi;
    when I use the sizeof operator to get the size of a structure
    it returns a size too large why is this?

    Thanks.

  2. #2

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Quote Originally Posted by learncode View Post
    when I use the sizeof operator to get the size of a structure
    it returns a size too large why is this?
    Structures are typically padded with additional bytes for alignment purposes.

    Unless the structure members are sized and ordered with perfect alignment, or you go out of your way to pack the structure, having a larger size than the sum of each member's size is expected.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sizeof a struct
    By stanlvw in forum C++ Programming
    Replies: 7
    Last Post: 04-09-2009, 01:58 PM
  2. Why sizeof() this struct is 12 ?
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 04-08-2008, 04:23 AM
  3. sizeof struct
    By k_w_s_t_a_s in forum C Programming
    Replies: 9
    Last Post: 05-29-2003, 04:36 PM
  4. sizeof struct
    By k_w_s_t_a_s in forum C++ Programming
    Replies: 3
    Last Post: 05-11-2003, 12:05 PM

Tags for this Thread