Tuesday, January 15, 2008

CSE 2031 Lecture 3

  • Integer types:
    • char
    • short
    • int
    • long
  • Floating point types:
    • float
    • double
    • long double

Char

  • 1 byte long
  • char<= short<=int<=long
  • denote characters in single quotes
  • \0 is a null character
  • char *b = "TEST";
    • is a string writer (assumption)
  • EOF
    • Reads as -1
      • Which is an array of ones
  • getchar() reads a byte of unsigned chars and stores 4 bytes to represent them
    • the promotion to int is done as a signed char
    • This is because of things like EOF
  • A signed char
    • Fills the other bytes with the first bit of the signed char
    • If it is signed and starts with 0
      • It is non negative
    • If it starts with 1
      • It is a negative number
  • An unsigned
    • Does not fill the other 3 bytes with the first bit but with all 0's when promoted to an int

Declarations

  • when you declare a variable in C it is visible throughout the score of the brackets that it is withheld
  • if you want a variable to be visible throughout a program put it above the main
  • to make one variable local to a file use the word 'static'

String

  • an array of char
  • there is no 'String' in C

Arrays

  • to declare an array in C
    • use type name[size]
      • example: int number[10]
  • you can initialize an array w/o a specified size
    • char s[] = {'h','e','l','l','o','\0', 'q'}
    • printf("%s /n", s}
      • returns 'hello'
        • note there is no q, that is because null character was before it

printF

  • %d prints integers
  • %s prints char characters
    • Prints until it finds a null character
    • Null character is \0
  • %p prints the address

Console

  • Od –cb filename
    • Describes a file in bits

No comments: