如何引用串变量并在有或没有指针的情况下进行敲击
How to reference the stuct variable and intailize with or without pointer
struct aes_key_st {
#ifdef AES_LONG
unsigned long rd_key[4 *(AES_MAXNR + 1)];
#else
unsigned int rd_key[4 *(AES_MAXNR + 1)];
#endif
int rounds;
};
typedef struct aes_key_st AES_KEY;
上面的代码存储在samp.h中为struct,并分配给aes_key。
在其他名为samp.c的文件中,我需要访问以上如下所示
int main(void)
{
AES_KEY enc;
}
以上是样本零件我的问题是
- 如何将值分配给ENC变量。
- 如何将值分配给ENC作为指针变量。
您的问题不是很清楚。但是,给定您的代码:
int main(void)
{
AES_KEY enc;
AES_KEY *enc_ptr = &enc; // make a pointer to enc
enc.rounds = 0; // Assign to the 'rounds' field of record AES_KEY
enc_ptr->rounds = 3; // Overwrite the 'rounds' field via a pointer
enc.rd_key[0] = 1 ; // Assign a value to the first element of the 'rd_key' array
enc_ptr->rd_key[0] = 2 ; // Overwrite the same element via a pointer
}
是你在问什么?
相关文章:
- 我是c ++的新手,你能解释一下在这种情况下的指针吗
- 如何在没有数据拷贝的情况下从指针创建一个Eigen VectorXd对象
- 模板方法访问正向声明的类仅在没有此指针的情况下无法编译
- C++默认情况下,指针类型数组的元素是否保证初始化为 nullptr?
- 如何在不使用指针的情况下将派生类的对象作为参数传递给基类中的函数?
- 使用指针在存在特征库的情况下动态分配 c++ 中的矩阵
- 在什么情况下,需要共享智能指针而无法使用唯一指针?
- 为什么或在什么情况下,你会将参数作为C++中的引用(或指针)传递给函数?
- 如何在不使用临时变量的情况下取消引用返回指针的函数的返回值?
- 我们可以在不知道其真实类型的情况下将基类指针转换为派生类指针吗?
- 有没有办法在没有虚拟的情况下使用基类指针调用派生类函数
- 在这种情况下,当尝试从单独的类更新变量时,我是否需要使用指针?
- 我们可以在不使用head指针的情况下通过使用head的简单变量而不是head的指针来实现链表吗
- 在不工作的情况下为数组分配指针,但反过来也可以
- 对于多态类型T,如何在没有类型T实例的情况下获得指向T的虚拟表的指针
- 为什么不能指向指针,在没有强制转换的情况下访问结构成员?
- 有没有办法在没有reinterpret_cast的情况下保存多种类型的指针?
- (C++)如何在不导致 mem 泄漏的情况下将指针传递到分配了'new'的函数?
- C++:为什么可以在没有事先使用 new 的情况下在指向结构的指针上使用 delete?
- 在C++我可以在不在本地声明结构的情况下将结构作为指针传递吗?