I am a bit confused here; I have this expression

! (1 && !(0 || 1))

What would this evaluate?

I tried to see it in logic as I go the steps:

NOT (1 AND NOT(0 OR 1)) //0 NOT 1? what is this mean? How I can evaluate 0 NOT 1?

Will this expression give me true? false or just not compiled?

Anyone?

Recommended Answers

All 8 Replies

It evaluates to true. Work from inside out. Note 1 = true, 0 = false

Initial expression : (! (1 && !(0 || 1))) inner most expression is (1 && !B) where B = (0 || 1) Since 1 = true, !B also needs to be true inorder for 1 && B to be true. So lets check out B. B = (0 || 1) evaluates to true, because for the OR operator only one of the operands needs to be true. Since there is a 1 there, the whole B expression is true.

So now we have (1 && !1) , we just substituted B for true, and that expression turns into (1 && 0) which is false. Now we plug this into the initial expression : (!(1 && 0)) = !(0) = 1 = true

Thanks a lot very good explanation! Much appreciated!!

! (1 && !(0 || 1))

Do it according to the precedence. SO here First of all

(0||1)

This give you true, since only one of them need to be one, but it is given with NOT "!", so it give false.

Now You have
!(1&&0)

(1&&0), this evaluates to False ("0") because for it to be true, at both sides it should be 1.

So Finally !(1&&0) evaluates to TRUE "1".

Can someone clarify me:

If for example I have code e.g:

class foo {
    int val; 
}

How do I know / tell if the member variable val declared as: private? public? protected or is it undefined? And explain why it is the one you say it is.

Can anyone explain on this? Thanks.

It will be a private, this is the default behavior. Any member of your class will be private by default, even your constructors.

It will be a private, this is the default behavior. Any member of your class will be private by default, even your constructors.

I see okay, isn't the default would be public?

So if we did not define the behaviour of the class then it will automatically put into private?

I see okay, isn't the default would be public?

I know it's kind of surprising, but when it comes to object oriented programming it make sense. It is safe to say that, most of the time you want to separate your objects data from each other as much as possible. Because they are different from each other, you don't want to allow just any kind of operation on them, it might mess up your data, or it could cause unreliable, unsafe behavior.

There is another kind of data type, called structure. Structures and classes behave very much the same, the difference between the two is in structures everything is public by default, so you can access their members from anywhere. In classes opposed to structures everything is separated, private by default.

So if we did not define the behaviour of the class then it will automatically put into private?

That's correct, if you don't specify the access level of the members they will be private by default.

Thanks for the well explanation!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.