C/C++ and Java Comparison

A Dr. Taylor Tutorial

Much of the programming fundamentals learned in your Java software development classes apply directly to programming in the C language.

Language History

Similarities Between C and Java

Our discussion will be based a specific variant of C know as C99 (as implemented by the GNU GCC compiler).

Numeric Data Types

C provides numeric data types that are similar to those in Java.

In Java we have the following numeric data primitives:

Datatype Content Space Required Min Value Max Value
byte integer 8 bits -128 127
short integer 16 bits -32,768 32,767
int integer 32 bits -2,147,483,648 2,147,483,647
long integer 64 bits -9,223,372,036,854,775,808 9,223,372,036,854,775,808
float real 32 bits -3.4E38 3.4E38
double real 64 bits -1.8E308 1.8E308

In C, the space required by the int and long types depends on the target microcontroller. Also, we have some additional numeric data types:

Datatype Content Space Required Min Value Max Value
unsigned byte integer 8 bits 0 255
unsigned short integer 16 bits 0 65,535
unsigned int integer target dependent 0 ??
unsigned long integer target dependent 0 ??

The C99 standard introduces the following types which have a fixed space requirement. You should use these types in your code:

Datatype Content Space Required Min Value Max Value
uint8_t integer 8 bits 0 255
uint16_t integer 16 bits 0 65,535
uint32_t integer 32 bits 0 4,294,967,295
uint64_t integer 64 bits 0 18,446,744,073,709,551,615
int8_t integer 8 bits -128 127
int16_t integer 16 bits -32,768 32,767
int32_t integer 32 bits -2,147,483,648 2,147,483,647
int64_t integer 64 bits -9,223,372,036,854,775,808 9,223,372,036,854,775,808

Other Data Types

Java supports a few other primitive data types:

C language differences:

char word[] = "funness";

Variable Declaration and Initialization

Iteration and Selection

Mathematic Operations

Tutorials for Other Courses

Additional Links

Site Mirror

This is a mirror to be used when http://myweb.msoe.edu/taylor/, (EDU instead of US) is not available.