Docsity

Understanding Computer Components: Memory, Variables, and Data Types in C, Study notes of Computer Science

Partial preview of the text

Download Understanding Computer Components: Memory, Variables, and Data Types in C and more Study notes Computer Science in PDF only on Docsity!

Memory, Variables and Data Types

Lecture 4

September 10, 2007

Components of a Computer

Variables •^

Variables give names tomemory cells^ –

See text p.22 for rules for variablenames

-^

Variables declared in program^ –

sum

-^

result

-^

colorchar

-^

Declarations assign memory^ –

may also initialize values

C basic types •^

Writing values for the four basic types^ –

int sum =

  • Additional int numbers:

–^

float result =

  • Additional numbers:
  • Write double numbers in the same way as float• Can also use scientific notation 8.4e+ -^

char colorchar =

‘R’

  • Note single quotes for a character• Strings in printf use double quotes -^

Formatting codes for printf^ –

int -

%i or %d

–^

float and double -

%f

(or %e for scientific notation)

  • double can also use

%lf

–^

char -

%c