As I know, strucutre elements are stored in continuous memory locations. To confirm the same, I written below sample application.
#include <stdio.h>
struct Employee{
char firstName;
float salary;
int id;
};
int main(){
struct Employee emp = {'K', 123456.78, 1};
printf("firstName stored at location : %lu\n", &emp.firstName);
printf("salary stored at location : %lu\n", &emp.salary);
printf("id stored at location : %lu\n", &emp.id);
return 0;
}
When I ran the application, I seen below kind of output.
firstName stored at location : 140732780083504
salary stored at location : 140732780083508
id stored at location : 140732780083512
As you see the output, firstName stored at location 140732780083504, and salary stored at location 140732780083508, can't the salary be at 140732780083505? Is the behavior like it always return end location of specific variable.