notes2 - Lexical Structure of C A program is a sequence of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lexical Structure of C A program is a sequence of characters in a text file. hello.c |*. ..... *| int main() { printf(“Hello World\n”); } The Compiler groups characters into units called “tokens”(lexical units). Comments /*. ..... */ same as Java //. ..... available in most compilers but it is not in standard. Identifiers Sequence of letters, underscore and digits that do not start with a digit Only first 37 chars are significant Mix lower and upper case characters to make variable readable Keywords Special words. while,break, for, case, break,continue, int. ..... Types Integer types you may use the qualifier short or long , unsigned or signed . Example: short unsigned int x; signed long y; int e; C guarantees that size(short) <=size(int) <= size(long) Usually, sizeof(char) = 1 bytes sizeof(short) = 2 bytes sizeof(int) = 4 bytes(32bit arch.)/8 bytes(64 bit arch) Character Types char → 1 byte -128. ..127
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
unsigned char → 1 byte 0. ..255 signed char → 1 byte -128. ..127 Floating Point Types float, double C guarantees that sizeof(float) <= sizeof(double) <= sizeof(long double) Usually, sizeof(float) → 4 bytes sizeof(double) → 8 bytes sizeof(long double) → 16 bytes Declaration of Variables Same as Java. int I; double d = 1.23; Constants Same as Java. const double PI = 3.14192654; *constant cannot be changes Also it is common in C to use C pre-processor to define variables #define PI 3.14192654 Assignment
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 7

notes2 - Lexical Structure of C A program is a sequence of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online