[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

what is the difference between =! and != in C? when I write

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 23
Thread images: 2

File: tiger.jpg (47KB, 600x503px) Image search: [Google]
tiger.jpg
47KB, 600x503px
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.
Thread posts: 23
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.