I was going through the questions in my study guide for computer science, and I noticed a few blocks of code that contained syntax that I had never used before.

My first question is on the ^ operator.
What exactly does this do?

My second questions is on the use of : and ? in if and for statements.
What exactly do these operators do?

Here are the blocks of code that they are featured in: int x= 2^3;


If someone could atleast point me to a web page that explains those operators, I would much appreciate it.

^ is a bitwise XOR operator. It can only be used on primitive integer types.

?: is the ternary operator, so named because it takes three parts (see example below). It's shorthand for an if-else clause.

// can also be done as:
condition ? foo() : bar();

Thanks; I should be able to find any other information with what you have given me.

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.