W2 - TYPES (AND VARIABLES); A SIMPLE CALCULATION; EXPRESSIONS Flashcards

1
Q

W2-1 Why C is a “TYPES PROGRAMMING LANGUAGE”

A

Each type has its own rules:
▪ How values are stored in memory
▪ What operations can be used on that type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

W2-2 Two common MAIN groups of data types?

A

(a) Integral: Whole numbers: 1, 13, 157 …

(b) Floating-Point: Fractional numbers: 1.1,13.304, 157.54648 …

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

W2-3 The COMPONENTS of the CPU?

A

(a) ALU (Arithmetic and Logic Unit)
▪ Integral types only (whole numbers): int, char

(b) FPA (Floating Point Accelerator)
▪ Floating-point types only (fractional numbers): float, double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

W2-4: Four Common data types

A

char (1-byte)
int (4-bytes)
=> intergral => ALU

float (4-bytes)
double (8-bytes)
=> floating-point => FPA

*** further fine-tune memory allocation size by using SIZE SPECIFIERS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

W2-5: TYPES

A
_ Integral Size Specifiers (int type only) 
1/ short (int): 2 bytes
2/ int: 4 bytes
3/ long (int): 4 bytes
4/ long long (int): 8 bytes
=> Not applicable to char

_ Floating-Point Size Specifier (double type only)
1/ double: 8 bytes
2/ long double: 8 bytes
=> Not applicable to float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

W2-6: SPECIFIERS

A

SPECIFIERS are an available option to ensure a MINIMUM memory allocation size is reserved when the variable is declared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

W2-7: Constant Value (const)

A

▪ A value which cannot be changed

▪ Reserved keyword/qualifier: const

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

W2-8: Variable

A

A VARIABLE is a named placeholder (identifier) for the STORAGE and retrieval of data held in memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

W2-9: Type: char (1 byte or 8-bits)

A

_ Treated as an INTEGRAL type (integer) using a collating sequence table where each CHARACTER or symbol is given a unique INTEGER value

_ Collating Systems:
1/ ASCII (most popular and aligns with newer Unicode standards)
2/ EBCDIC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

W2-10: Variable Naming Restrictions

A

▪ 1st character must start with:
– UPPER/lower case letter OR
– Underscore (_)
=> Invalid: int 3LegStool = 1;

▪ 2nd character onward can contain:
– UPPER/lower case letters
– Numbers (0-9)
– Underscore (_)
=> Invalid: int three-Leg-Stool = 1;

▪ Length of name < 32 characters (to ensure portability)
▪ Name cannot be a C reserved word

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

W2-11: Character Constants

A

▪ Digit or letter enclosed in SINGLE quotes: ‘A’ (this is the preferred way)
▪ Decimal value (base 10): 65
– ASCII table value for uppercase letter A
▪ Hexidecimal value (base 16): 0x41
– ASCII table value for uppercase letter A

EX:
1/ char exQuote = ‘A’; // system will lookup the collating sequence value
2/ char exDec = 65;
3/ char exHex = 0x41; // “0x” denotes hexadecimal values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

W2-12: Escape Sequences

A

▪ These SPECIAL constants define ACTIONS and symbols

▪ The BALCKLASH () identifies the ESCAPE sequence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

W2-13: Constant String Literals

A

▪ A sequence of characters enclosed in DOUBLE quotes

EX: printf(“Welcome to IPC144\n”);

_ Also includes an ESCAPE sequence for a NEWLINE constant character (\n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

W2-14: Input

A

scanf( format, address );

▪ Procedure used to capture values from the standard input DEVICE (keyboard)
▪ format argument: The expected INPUT value type
▪ address argument: STORES the input value to the specified variable’s ADDRESS

EX:
int age;
scanf(“%d”, &age);
• Prefix & specifies the memory address of a variable
• Age is the variable to store the value to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

W2-15: Output

A

printf( format, expression );

▪ Procedure used to DISPLAY values to the standard output device (monitor)
▪ format argument: Specifies how to CONVERT data into READABLE text
▪ expression argument: Supplies the data value to be TRANSALATED to the OUTPUT device

EX:
int age = 19;
printf(“Your age is %d”, age);

_ Source variable to be converted to text
NOTE: There is NO (&) used as this procedure requires a value not an ADDRESS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

W2-16: Expressions

A

▪ Should contain at least ONE operator and one or more operand(s)

_ Operators (3 most common): Arithmetic, Relational and Logical

_ Operands: Can be a combination of variables, constants and other expressions

17
Q

W2-17: Arithmetic Expressions

A

Order of operator EVALUATION

  1. Brackets: ( )
  2. Multiplication: * Division: / Modulus: %
  3. Addition: + Subtraction: -
  4. Assignment: =
18
Q

W2-18: Conversion

A
▪ Explicit
– Casting (programmer specifies the type)
EX:
float balance = 5.75f;
int loonies = (int)balance;

▪ Implicit
– Coercion/implied (rely on compiler and standards to determine the type)

19
Q

W2-19: Conversion

A
▪ Promotion
EX: 
double balance;
int loonies = 50;
balance = loonies; // loonies gets promoted to double (50.0)
▪ Narrowing
EX: 
double balance = 57.75;
int loonies;
loonies = balance; // balance gets truncated to an int

Result: loonies = 57; // 57.75 the .75 is “chopped” NOT rounded