lecture03-jan25 - EE312 - Lecture 3 Announcements Read...

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

View Full Document Right Arrow Icon
1 EE312 - Lecture 3 Announcements • Read chapters 3 and 4 in the book • Assignment 1 due on Thursday • TA Office hours are posted on the BB • Topics for today will address: – Data type basics – Declaration statement – Assignment statement – Numerical expressions – Number storage formats (details in Ch. 7) – Will use these formatted IO functions in examples: printf( . . . ) - output values to the screen scanf( . . . ) - input values from the keyboard • These are in Ch. 3 (read it) and will be covered next time Built-in Data Types in C • A variable is a symbolic name for a type of value that can change as your program runs. – It must be declared and given a data type before use – Some variables hold numeric values • C supports two different types of numbers: – integers: …, -2, -1, 0, 1, 2, …. • Several memory formats available – Foating point (real) numbers: -1.232, 3.14159 • two memory formats for these ( foat and double ) • Numbers can also appear as literal values in a program • The other two non-numeric data types are char , and void - more details on these later Data Declaration Statement • To define a new variable to be of a particular data type. – The variable is then known (accessible) in the function/block in which it is declared. • Proper syntax: typeName variableName ; • VariableName must be a legal identifier; typeName a legal keyword identifier for one of the built-in types • Can also be a list of variableNames separated by “,”s for a given typeName • Initial values can optionally be supplied [ = value ] • Examples int year ; float price; double radius = 15.99 ; int a, b, c; int courseNumber = 312; Assignment Statement int x =1, y = 6, z = 7; /* declaration and initialization */ double radius; x = x + 1; /* Add 1 to the current value of x;*/ radius = 1.0; /* Assign 1.0 to radius;*/ y = x * z + 14 – y % 5 + z / 4 ; variableName = expression ; The expression on the right hand side can be a variable, a constant, a literal or a combination of these connected by operators (e.g. a formula). It can contain sub-expressions. The variableName must have been previously declared. The = symbol is NOT equality in C. If variableName and expression don’t have the same data type, then the value of the expression is automatically converted before the assignment is done: int i; Foat f; i = 72.99; /* i is now 72 */ f = 136; /* f is now 136.0 */ Assignment For example, the statements float total; int quarters; total = 0.0; quarters = 12; total = total + quarters * 0.25; means take the value in quarters, multiply it by 0.25, add that result
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

lecture03-jan25 - EE312 - Lecture 3 Announcements Read...

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

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