在一类列表中,b = a-> b是什么意思?
我正在阅读的示例是列表中的析构函数,并且在其"while"循环中它具有此操作.
Clistint::~Clistint(){
Clist *actual, *next;
if(head!=NULL){
actual=head;
while(actual!=NULL){
next=actual->next;
delete actual;
actual=next;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在编程一个锁,在哪里解锁它你必须在键盘中插入一个 PIN 码。我有以下变量:
char password_init[4] = {'1', '2', '3', '4'}; //initial password
char password[4];
Run Code Online (Sandbox Code Playgroud)
当用户按下键盘上的某个键时,该数字将存储在变量中,password并且在用户按下 4 位数字后,将比较两个变量,以确定是否可以访问锁定。
我发现这样做的一种解决方案是使用 strncmp() 函数:
if (!(strncmp(password, password_init, 4))){
Serial.println("PIN Code correct");
}
Run Code Online (Sandbox Code Playgroud)
这有效,但我不明白为什么我应该使用!(strncmo())而不是strncmo(). 如果我使用if (strncmp(password, password_init, 4)),结果将是错误的 PIN 码。
该strncmp()函数逐个字符地比较两个字符串,所以有人可以解释我为什么必须以否定方式使用它来代替初始密码和用户在键盘匹配中按下的密码吗?