Int a 12345 0x11ffffcb8 0x11ffffcb9 0x11ffffcba

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 3 * size of int) array_ptr = big_array + 3; 0x00ff000c (adds 3 * size of int) *array_ptr = *array_ptr + 1; 0x00ff000c (but big_array[3] is incremented) array_ptr = &big_array[130]; 0x00ff0208 (out of bounds, C doesn’t check)   In general: &big_array[i] is the same as (big_array + i), which implicitly computes: &bigarray[0] + i*sizeof(bigarray[0]); Memory 38 University of Washington RepresenJng strings   A C ­style string is represented by an array of bytes.   Elements are one ­byte ASCII codes for each character.   A 0 value marks the end of the array. 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 space ! # $ % & ( ) * + , . / 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 @ A B C D E F G H I J K L M N O 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 Memory P Q R S T U V W X Y Z [ \ ^ _ 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 ` a b c d e f g h I j k l m n o 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 p q r s t u v w x y z { | } ~ del 39 University of Washington Null-terminated Strings   For example, Harry Potter can be stored as a 13-byte array. 72 114 114 121 H   97 a r r y 32 80 111 116 116 101 114 0 P o t t e r \0 Why do we put a 0, or null, at the end of the string?   Note the special symbol: string[12] = '\0’;   How do we compute the string length?? Memory 40 University of Washington CompaJbility char S[6] = "12345"; Linux/Alpha S 31 32 33 34 35 00     Sun S 31 32 33 34 35 00 Byte ordering (endianness) is not an issue for standard C strings (char arrays) Unicode characters – up to 4 bytes/character   ASCII codes sGll work (leading 0 bit) but can support the many characters in all languages in the world   Java and C have libraries for Unicode (Java commonly uses 2 bytes/char) Memory 41 University of Washington Examining Data RepresentaJons   Code to print byte representaJon of data   Any data type can be treated as a byte array by casGng it to char void show_bytes(char *start, int len) { int i; for (i = 0; i < len; i++) printf("%p\t0x%.2x\n", start+i, *(start+i)); printf("\n"); } void sho...
View Full Document

Ask a homework question - tutors are online