numStudents, firstName // good a, ns, fn // bad
int numStudents; // variable of type integer double weight; // variable of type double char letter; // variable of type character // Examples of multiple variables of the same type in single // declaration statements int test1, test2, finalExam; double average, gpa;
int numStudents; double weight; char letter; numStudents = 10; weight = 160.35; letter = 'A';
int numStudents = 10; double weight = 160.35; char letter = 'A'; int test1 = 96, test2 = 83, finalExam = 91; double x = 1.2, y = 2.4, z = 12.9;
More Declaration
Examples, using various types
const int SIZE = 10; const double PI = 3.1415; // this one is illegal, because it's not // initialized on the same line const int LIMIT; // BAD!!! LIMIT = 20;
#define PI 3.14159 #define DOLLAR '$' #define MAXSTUDENTS 100
#define SIZE 10 const int SIZE = 10;
| Escape Sequence |
Meaning |
|---|---|
| \n | newline |
| \t | tab |
| \r | carriage return |
| \a | alert sound |
| \" | double quote |
| \' | single quote |
| \\ | backslash |
/* This is a comment.
It can span multiple lines */
int x; // This is a comment
x = 3; // This is a comment
This style of comment was not originally available in C. It was added
into the language later, and most compilers now support it.