Like Tree1Likes
  • 1 Post By laserlight

why the output is 32?

This is a discussion on why the output is 32? within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { struct jb{ char actor[25]; struct jb *next; }; struct jb ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    5

    why the output is 32?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main()
    {
        struct jb{
            char actor[25];
            struct jb *next;
        };
        struct jb *bond;
        int n;
        /* Create the first structure in the list */
        bond = (struct jb *)malloc(sizeof(struct jb));
        printf("struct jb sizeof is %d\n", n = sizeof(struct jb));
        printf("struct bond->actor sizeof is %d\n", n = sizeof(bond->actor));
        printf("struct bond->next sizeof is %d\n", n = sizeof(bond->next));
        /* Fill the structure */
        strcpy(bond->actor, "Sean Connery");
        bond->next = NULL;                        /* End of list */
        /* Display the results */
        printf("The first structure has been created:\n");
        printf("\tbond->actor = %s\n", bond->actor);
        printf("\tnext structure address = %p\n", bond->next);
        return(0);
    }
    the output:

    struct jb sizeof is 32

    ...

    but the array is 25, and pointer is 4, why the struct jb sizeof is not 29?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,803
    iMalc likes this.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 08:26 AM
  2. How to edit output in struct and call for the output
    By andrewkho in forum C Programming
    Replies: 4
    Last Post: 03-16-2010, 10:28 PM
  3. terminal output not showing output properly
    By stanlvw in forum C Programming
    Replies: 13
    Last Post: 11-19-2007, 09:46 PM
  4. output a string to a standard output
    By sh4k3 in forum C Programming
    Replies: 3
    Last Post: 06-15-2007, 05:59 AM
  5. Replies: 3
    Last Post: 02-19-2003, 07:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21