Science & Technology Support
High Performance Computing
Ohio Supercomputer Center
1224 Kinnear Road
Columbus, OH 43212-1163
Table of Contents
•
•
•
•
•
•
•
•
•
Introduction
C Program Structure
Variables, Expressions, &
Operators
Input and Output
Program Looping
Decision Making Statements
Array Variables
Strings
Math Library Functions
•
•
•
•
•
•
•
•
•
User-defined Functions
Formatted Input and Output
Pointers
Structures
Unions
File Input and Output
Dynamic Memory Allocation
Command Line Arguments
Operator Precedence Table
2
C Programming
Introduction
•
Why Learn C?
3
C Programming
Why Learn C?
•
•
•
•
•
•
•
•
•
Compact, fast, and powerful
“Mid-level” Language
Standard for program development (wide acceptance)
It is everywhere! (portable)
Supports modular programming style
Useful for all applications
C is the native language of UNIX
Easy to interface with system devices/assembly routines
C is terse
4
C Programming
C Program Structure
•
•
•
•
•
Canonical First Program
Header Files
Names in C
Comments
Symbolic Constants
5
C Programming
Canonical First Program
•
The following program is written in the C programming language:
#include main() {
/* My first program */ printf("Hello World! \n");
}
•
•
C is case sensitive. All commands in C must be lowercase.
C has a free-form line structure. End of each statement must be marked with a semicolon. Multiple statements can be on the same line. White space is ignored. Statements can continue over many lines.
6
C Programming
Canonical First Program Continued
#include
main()
{
/* My first program */ printf("Hello World! \n");
}
•
The C program starting point is identified by the word main().
•
This informs the computer as to where the program actually starts. The parentheses that follow the keyword main indicate that