I read that the size of a struct is at least the sum of individual fields inside it, and it can be greater than that when using struct array for alignment. What is alignment, why does it add that so called padding, how does it make it faster?
This is the code
#include <stdio.h>
int main(void) {
typedef struct {
int a;
int b;
char *c;
} node;
node x;
x.a = 1;
x.b = 2;
x.c = "sahil";
printf("size is %d\n", sizeof(x));
}
when I use %f
instead of %d
, it shows 0
as output. Why so? When used with %d
as written above, it prints 16
.