hello everybody i am happy that in web world there exist such good programming forums and now question when i run only following code pragment
int *t;
std::cout<<sizeof(char)<<std::endl;
std::cout<<sizeof(double)<<std::endl;
std::cout<<sizeof(int)<<std::endl;
std::cout<<sizeof(t)<<std::endl;
it gives me result like this
1
8
4
4
totally 17 but when i test sizeof struct which contains these data types it gives me 24 and i am confused what is additonal 7 bytes?sorry for my bad english this is code
#include <iostream>
#include <stdio.h>
struct struct_type{
int i;
char ch;
int *p;
double d;
}s;
int main(){
int *t;
//std::cout<<sizeof(char)<<std::endl;
//std::cout<<sizeof(double)<<std::endl;
//std::cout<<sizeof(int)<<std::endl;
//std::cout<<sizeof(t)<<std::endl;
printf("s_type is %d byes long",sizeof(struct struct_type));
return 0;
}
thanks
:EDIT
i have updated my code like this
#include <iostream>
#include <stdio.h>
struct struct_type{
double d_attribute;
int i__attribute__(int(packed));
int * p__attribute_(int(packed));;
char ch;
}s;
int main(){
int *t;
//std::cout<<sizeof(char)<<std::endl;
//std::cout<<sizeof(double)<<std::endl;
//std::cout<<sizeof(int)<<std::endl;
//std::cout<<sizeof(t)<<std::endl;
printf("s_type is %d byes long",sizeof(s));
return 0;
}
and now it show me 16 bytes it is good or i have lost some important bytes?