Why is
byte someVar; someVar -= 3;
valid but
byte someVar; someVar = someVar - 3;
isnt?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
History: The name C is derived from an earlier programming language called BCPL (Basic Combined Programming Language). BCPL had another language based on it called B: the first letter in BCPL.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
Surprisingly, when you perform operations on bytes the computations will be done using int
values, with the bytes implicitly cast to (int)
first. This is true for short
s as well, and similarly float
s are up-converted to double
when doing floating-point arithmetic.
The second snippet is equivalent to:
byte someVar; someVar = (int) someVar - 3;
Because of this you must cast the result back to (byte)
to get the compiler to accept the assignment.
someVar = (byte) (someVar - 3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With