This page was last updated: November 29, 2005
Item | Fortran 77 | C |
---|---|---|
Usual data types | INTEGER, REAL, CHARACTER | int, float, char |
Double precision | DOUBLE PRECISION | double |
Pointer variables | none | int *, float *, char *, double * |
Structures | none | struct { ... } ; |
Case | Single case only | Upper and lower case sensitive |
Declarations | Integer = I-N | All variables must be declared |
Type casting | F = FLOAT( I ) | f = (float) i ; |
Type casting | I = IFIX( F ) | i = (int) f ; |
Array declarations | INTEGER I(10) | int i[10] ; |
Array indices | Start at 1 (eg, 1-10) | Start at 0 (eg, 0-9) |
Globals | COMMON statements | Declared outside of all routines |
Main program | Comes first in program | Looks like a subroutine called main( argc, argv ) |
Continuation | Character in column 6 | Statement terminated with ; |
Arithmetic | * / + - | * / + - |
Exponentiation | A ** B | pow( a, b ) ; |
Pointer arithmetic | none | &, * unary operators |
IF relations | .EQ. , .NE. , .GT. , .GE | == , != , > , >= |
IF relations | .LT. , .LE. , .AND. , .OR | < , <= , && , || |
Main looping | DO 100 I = 1, 10 | for( i = 1; i <= 10; i = i + 1 ) |
Continue next loop | GOTO 100 | continue ; |
Break out of loop | GOTO 200 | break ; |
Other looping | none | while and do...while |
Blocks of statements | Bounded by labels or then-endif | Bounded by { } |
Output | WRITE, FORMAT, ... | printf(...), fprintf(...) |
Input | READ, FORMAT, ... | scanf(...), fscanf(...) |
Pre-initialization | DATA statement | Global assignment |
Statement labels | Numbers | Names |
GOTOs | GO TO 1000 | goto proceed ; |
Use of GOTOs | Necessary often | Rarely necessary |
Constants | PARAMETER | #define |
Variables passed | By address | By copying the value |
Dynamic Mem Alloc | No | malloc(...), realloc(...) |
Switching | GOTO ( ... ), I | switch(i) { ... } |
Functions | IABS(I), ABS(F) | abs(i), fabs(f) |
Functions | SQRT(F) | sqrt(f) |
Functions | SIN(F), COS(F) | sin(f), cos(f) |
Functions | ATAN(F), ATAN2(F1,F2) | atan(f), atan2(f1,f2) |
Functions | EXP(F), ALOG(F), ALOG10(F) | exp(f), log(f), log10(f) |