valid code?

hey , everyone. I have a few questions about pieces of code and was wondering if someone could tell me what exactly they did or if they are even valid.

bool1 && bool2 || bool3 <---in what order do these get processed?
if (! isdigit(c)) <---What does this do?
i = j % 3; <---what does this do?
a+b *c <---what order do these get processed?

Are any of these lines valid code?
i;
short int s;
long int L;
long long LL;

thanks everyone.

bool1 && bool2 || bool3 <---in what order do these get processed?

Left to right: bool1 then bool2, if they both return true then bool3 is ignored.
If they fail then bool3 is tested

if (! isdigit(c)) <---What does this do?

returns true when C is any non-numeric character - punctuation, aplhabetic, etc.

i = j % 3; <---what does this do?

i is assigned the remainder (modulo) if the value of j divided by 3. ie if j is 5, 5 mod 3 = 2 - so 2 is assigned to the variable i.

a+b *c <---what order do these get processed?

multiplication then addition so a is added to the value of b*c

This sounds like homework....

bool1 && bool2 || bool3 

&& has higher precedence than || .Associativity is from left to right.
first bool1 && bool2 is executed and then with bool3.
If bool1 expression is false then bool2 expression is not executed.
If result of bool1 && bool2 is true then bool3 expression is not executed

if (! isdigit(c)) 

Negates the result of isdigit(c)

i = j % 3  

% modulus operator which gives the remainder

a+b *c
  • has higher precedence than +. Associativity is from left to right.
    Above one is similar to a + (b*c)

hey thanks, cleared that right up for me. what about those last few lines, are any of those valid code?

Oh, lol nope not homework, just wondering what would happen if i didn't put in brackets on some of these things. and what c is willing and not willing to do.

Only if there is a variable 'i' declared in scope. But while valid, it's totally useless, the statement has no effect.

The first two are valid. 'long int' is redundant, since 'long L' will declare the same type of variable. The actual sizes of the integers varies from platform to platform, but the order of sizes is always:

sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(void *) <= sizeof(long)

Note how sizeof(int) isn't guaranteed to be equal to siezof(void *) -- it can also be smaller. It's usually the same on 32-bit platforms, but assuming it's safe to cast pointer to int has caused many headaches on 64-bit systems, where pointers are suddenly twice as large!

If fixed sizes are needed for integers, like a guaranteed 32-bit type, use the types declared in stdint.h.

'long long' is a gcc extension for 64-bit integers on 32-bit platforms. Different compilers have different ways of doing this. Again, use the 64-bit type from stdint.h instead.