Lect-03-Variables and Datatypes
Lect-03-Variables and Datatypes
TRACING PROGRAM
Variables
Must declare variables before use
Variable declaration:
int a; - integer variable
long b; - long integer variable
short c; - short integer (16 bit)
float d; - floating point
double e; - double precision float
char f; - character type
Min Max
short int -32768 32767
unsigned short 0 65,535
int -2,147,483,648 2,147,483,647
unsigned int 0 4,294,967,295
long (32bit) -2,147,483,648 2,147,483,647
unsigned long (32) 0 4,294,967,295
long (64bit) −9,223,372,036,854,775,808 9,223,372,036,854,775,807
unsigned long (64) 0 18,446,744,073,709,551,615
float ±3.4028234e±38(8 decimal digit)
double ±1.7976931348623158e±308 (16 decimal digit)
Definitions (1/2)
Datatypes:
The datatype of an object in memory determines the
set of values it can have and what operations that can
be performed on it.
C is a weakly typed language. It allows implicit
conversions as well as forced (potentially dangerous)
casting.
Operators:
specify how an object can be manipulated(e.g.,, numeric
vs. string operations).
operators can be unary(e.g., - -,++),binary (e.g.,+,-
,*,/),ternary (?:)
Definition (2/2)
Expressions:
An expression in a programming language is a
combination of values, variables, operators, and
functions
Variables:
A variable is as named link/reference to a value stored
in the system’s memory or an expression that can be
evaluated.
Consider: int x=0,y=0; y=x+2;
x, y are variables
y = x + 2 is an expression
+ is an operator.
Names of variables (and questions)
Naming rules:
Variable names can contain letters, digits and _ (underscore)
Character (char)