如何引用串变量并在有或没有指针的情况下进行敲击

How to reference the stuct variable and intailize with or without pointer

本文关键字:指针 情况下 何引用 引用 变量      更新时间:2023-10-16
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;
}

以上是样本零件我的问题是

  1. 如何将值分配给ENC变量。
  2. 如何将值分配给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
}

是你在问什么?

相关文章: