Compe260 - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Compe260

Description:

represents integers from -128 to 127, negative numbers are stored using ... Indirection. Memory Requirements. The size of an address for a particular processor. ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 7
Provided by: brettb2
Category:

less

Transcript and Presenter's Notes

Title: Compe260


1
Lecture 4
  • Compe260

2
Char data Type
  • Memory requirements
  • 1 byte 8 bits
  • Permitted Operations
  • Same as signed integer
  • Char variable assignments may be
  • Numeric
  • represents integers from -128 to 127, negative
    numbers are stored using 2s complement notation.
  • char cVar 0x30
  • If a char is to be used numerically, use a
    typedef
  • typedef char INT8
  • INT8 cVar 0x30 //this is clear
  • ASCII
  • char cVar 0 //stores ASCII code for 0
    (0x30)
  • Strings are arrays (consecutive sequence) of
    characters where the last character of the string
    is an ASCII NULL
  • char myString this is a string declaration
    //allocates and initializes 29 bytes of // memory
    for the string
  • Char myString a, b, c, 0

3
unsigned char data Type
  • Memory requirements
  • 1 byte 8 bits
  • Permitted Operations
  • Same as unsigned integer
  • Char variable assignments may be
  • Numeric
  • represents integers from 0 to 255.
  • unsigned char ucVar 0x30
  • If an unsigned char is to be used numerically,
    use a typedef
  • typedef unsigned char UINT8
  • UINT8 ucVar 0x30 //this is clear

4
sizeof operator
  • Returns the number of bytes of storage required
    to hold a variable of a given type.
  • sizeof(int) returns the number of bytes required
    to store an int.
  • All memory is allocated in multiples of bytes.
  • Bits 2Bytes
  • Bytes log2(bits)
  • For unsigned integer (char, short, long) types
  • Maximum value is 2Bits 1
  • Range of values 0 lt x lt 2Bits 1

5
Arrays
  • An array is a collection of data of the same
    type.
  • Values in the collection can be operated on using
    index or pointer notation.
  • Name of the array is a pointer to the first
    element of the array.
  • UINT16 myVar10 //allocates 10 2 bytes of
    memory
  • myVar is the same myVar0
  • Index notation is clearer and recommended.
  • Memory Requirements
  • Number of array elements sizeof(data type)
  • Permitted operations
  • Programmer may manipulate each element using
    operations defined for the underlying data type.

6
Pointers
  • Pointers store the address of a variable.
    Pointers access the contents of a variable
    indirectly by reference.
  • Indirection
  • Memory Requirements
  • The size of an address for a particular
    processor.
  • Use sizeof operator to determine exactly.
  • Operations
  • Arithmetic , , -, --, etc
  • Numbers refer to the size of the underlying data
    type.
  • Danger do use an unassigned pointer
  • Interesting fact
  • A pointer can be used as the base pointer of an
    array.
  • int myIntPtr, intArray10, myInt
  • myIntPtr intArray3 //assign the pointer to
    reference the 4th element
  • myInt myIntPtr0 //store value of 4th element
    of the array in myInt
Write a Comment
User Comments (0)
About PowerShow.com