what is the difference between =! and != in C?
when I write " current->next =! NULL " it gives no error when compiling but the program crashes. I dont understand why it even compiles.void push(node_t *head, int val) {
node_t *current = head;
node_t *new = malloc(sizeof(node_t));
if (new == NULL){
return(1);
}
while ( current->next != NULL){
current = current -> next;
}
current -> next = new;
new -> next = NULL;
new -> val = val;
}
!= is a comparison operator, while =! sets a variable to the NOT of the right side
fag != NULL is different to
fag = !NULL
>>58266202
so it sets it to any random variable that is different from the left side?
>>58266202
this
it's not =! null but = !null
>>58266225
It sets it to the NOT of the right side variable, NOT is an operation like AND/OR/XOR/etc, basically just flips the bits of the variable
So if you had fag =! 0, that would set fag to the NOT of 0 which should be 0xFFFFFFFF, and vice versa I suppose
>>58266225
No, it sets it to !NULL. Which is 1. Which is not a sensible pointer value, and breaks when you try to dereference it.
>>58266225
it sets it to 1 if right side is equal to 0 and to 0 if right side > 0
Hahaha, you're fucking dumb.
>>58266243
No, that's the ~ operator, not the ! operator. The ! operator maps 0 to 1 and anything else to 0. So !NULL is 1, not 0xffffffff or anything like that.
>>58266248
s/>/!=
i += 1;
is different from
i = +1;
>>58266260
Oh yeah your right, knew I had something wrong after posting that
But yeah anyway OP, IIRC there's no actual valid comparison operators that start with =, other than "==" ofc (the rest are <= >= != etc)
So if you ever see an if statement that has an operator starting with "=" it's safe to say that the statement is setting the variable instead of comparing it, which some compilers will warn about but not all
ok I got it . thanks.
x =! NULL = 1
>>58266329
Yes but to be pedantic
(!NULL == 1) == true
x = !NULL
(x == 1) == true
>>58266175
!= 5 means "NOT equal to 5"
=! 5 means "equal to NOT 5"; it is equivalent to = !5
>>58266414
What the fuck is !5? Wouldn't that give an error?
>>58266557
Logical unary NOT returns 1 if given a non-zero operand, and 0 otherwise. That's all.
>>58266579
Oops. Other way around.
It's late.
>>58266557
Any primitive type in C can be treated as a boolean. That includes integers and pointers. The bool type didn't get introduced until C99.
>>58268229
>18 years later and we still use 28 years old language
Seems like fine.
>>58270097
Just because something is old does not automatically make it bad.
>>58266175
Can you stupid cturds please stop re-implementing the fucking linked list over and over again?
Not only is it a problem that has been solved millions of times already, the linked list as a data structure sucks ass.
I'm starting to wonder if linked lists are the only thing the average /g/ c programmer can program.
>>58270919
And every time niggers are reimplementing and reimplementing Booleans just because they don't use modern languages.