Tutorial

From Ubcacm
Jump to: navigation, search

Compiling the Program

C

gcc <input.c> -o output -Wall

C++

g++ <input.c> -o output -Wall

Note that attempting to compile a C++ file with gcc will fail with undefined reference to `__gxx_personality_v0'

-Wall turns on all compiler warnings, It is not necessary, but often useful to catch silly mistakes in the code.

Java

javac <input.java>

Data Representation

Numbers

Boolean

Integers

Fixed Length
  • char: 8 bits in C/C++, 16 bits in Java
  • int: 32 bits
  • long: 32 bits in C/C++, 64 bit in Java
  • long long: 64 bits in C/C++, GCC only. (__int64 in Microsoft C++)

An n-bit signed integer can represent values int the range [-2n-1, 2n-1 - 1].
An unsigned integer can represent values in the range [0, 2n - 1] (Not available in Java)
Values are represented in 2's complement (mod 2n) during overflow.

Division rounds towards 0

    • (-5) / 3 = -1
    • 7 / 3 = 2
    • 1 / 2 = 0
Arbitrary Length

Java has BigInteger

  • This is slow, but infinitely precise.

Floating Point

Strings

Structures

Classes