Our reference
- Chapters 1 to 6 and 13 of An Introduction to the C Programming Language and Software Design
But let’s start with some Fall 2015 CSCI 255 notes on C vs Java or the Fall 2011 ECE 209 C overview.
Chapter 1 — Introduction
- Designed to compete with assembly language
- Has a
goto - No objects
if,whileandfor- but
the condition is an
intnot aboolean
- but
the condition is an
- C preprocessor
Chapter 2 — Types, Operators, and Expressions
This discussion applies to the C99 standard. Before C99, it was chaos.
- Integers and characters
- C has similar integer types to Java but is quite a bit more flexible about the range of allowed values. See Wikipedia for more information.
-
There are
signedandunsignedinteger values. This can be useful. Javashort,int, anddoubletypes are unsigned. -
C has no
booleantype. A non-zero integer is considered to be true and0is considered to be false. C99 does have a “type”_Boolthat is similar to the Javaboolean. - There is no
bytein C. - Java
charis like a Cunsigned short.
- Standard C I/O is important and influenced Java I/O (more O than I)
- C and Java have similar cast operations, but narrowing without cast is allowed in C.
Chapter 3 — Branching and Iteration
- Looks like Java with a
goto.
Chapter 4 — Functions
- functions are not methods.
-
C has function prototypes to specify the
function interface.
-
See
fprintfman page.
-
See
- The
mainfunction returns an integer to indicate success or failure - C standard library has many useful functions.
Chapter 5 — Scope and Extent
This is not Java.
Chapter 13 — Input and Output
%[flags][width][.precision][length]specifier- The C/C++
printfis a bit like the Javaformat
- The C/C++
-
%[*][width][length]specifier-
The C/C++
scanfis very different from the JavaScanner - C input uses pointers
-
The C/C++
- Blame it all on FORTRAN
- In practice C++ I/O, with its heavy use of operator overloading and multiple inheritance, resembles neither C nor Java I/O
-
File control:
fopenandfclose - Stream access
-
Random access:
fseekandftell - Command line arguments
- Let‘s look at some Fall 2010 ECE 209 formatting notes
C I/O example from Fall 2017
Pay attention! This is a department required assignment.