Hot answers tagged

8 votes
Accepted

What happens under the hood when performing a cast?

Lets say you have the following code: short myShort = 23948; byte myByte = (byte)myShort; mybyte will contain the value 140. Short is a 2-byte type and a byte is a single byte. When you cast from ...
user avatar
  • 483
6 votes
Accepted

Can't cast a float to an int?

Your code isn't working for the same reason that this code: int x = 5; x + 5; printf("%i", x); does not print the number 10. In C, (int) is a type casting operator; much like the + operator, it ...
user avatar
  • 2,136
2 votes
Accepted

Pset4 error: invalid operands to binary expression ('double' and 'double (*)(void)')

drand48 is a function that takes no arguments and returns a double. It's declared in stdlib.h. You should call it like drand48();
user avatar
  • 17.4k
1 vote
Accepted

PSET 4 - Filter Grayscale

The reason is that if the code is doing division with all integers, it will do integer division, not normal division. Integer division will truncate the fractional part of the division. So, if the ...
user avatar
  • 63.5k

Only top scored, non community-wiki answers of a minimum length are eligible