Sunday, October 2, 2011

Data Alignment and performance optimization: C source code, concept


/*Check out the following code. This code is an example of data alignment in C. Read out more at http://www.codeguru.com/forum/showthread.php?t=276622  */
#include<stdio.h>

struct stud1
{
    double fee;
    char branch_code;
    float marks;
    int b1;
    int b2;

};

struct stud2
{

    char branch_code;
    double fee;
    float marks;
    int b1;
    int b2;

};

struct stud3
{

    char branch_code;
    float marks;
    int b1;
    int b2;
    double fee;

};
main()
{
    printf("%d %d %d",sizeof(struct stud1),sizeof(struct stud2),sizeof(struct stud3));
}
//Compile it, and check the output. If you are surprised, have a look at http://www.codeguru.com/forum/showthread.php?t=276622

No comments:

Post a Comment