题解 | #嵌入式结构体对齐#
嵌入式结构体对齐
https://www.nowcoder.com/practice/0d560f3c8cf74c78992101f93b8338f8
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @param d double浮点型
* @param c char字符型
* @return int整型
*/
#pragma pack(1) //设置结构体的边界对齐为一个字节
typedef struct
{
char c;
int i;
double d;
} str_t;
int smaller_space(int n, double d, char c ) {
// write code here
str_t s1;
s1.c=c;
s1.d=d;
s1.i=n;
return sizeof(s1);
}
查看21道真题和解析