题解 | #嵌入式结构体对齐#
嵌入式结构体对齐
https://www.nowcoder.com/practice/0d560f3c8cf74c78992101f93b8338f8
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param d double浮点型 * @param c char字符型 * @return int整型 */ #include <string.h> struct Nowcoder { char n[4]; char d[8]; char c; }data; int smaller_space(int n, double d, char c ) { // write code here memset(data.n, n, sizeof(data.n)); memset(data.d, d, sizeof(data.d)); data.c = c; return sizeof(data); }