Arrays and Pointers in C - Rice University
Arrays and Pointers in C
Alan L. Cox alc@rice.edu
Objectives
Be able to use arrays, pointers, and strings in C programs
Be able to explain the representation of these data types at the machine level, including their similarities and differences
Cox
Arrays and Pointers
2
Arrays in C
All elements of same type ? homogenous Unlike Java, array size in declaration
int array[10]; int b;
array[0] array[9] array[10] array[-1]
= 3; = 4; = 5; = 6;
Compare: C: int array[10]; Java: int[] array = new int[10];
First element (index 0) Last element (index size - 1)
No bounds checking! Allowed ? usually causes no obvious error
array[10] may overwrite b
Cox
Arrays and Pointers
3
Array Representation
Homogeneous Each element same size ? s bytes
An array of m data values is a sequence of ms bytes Indexing: 0th value at byte s0, 1st value at byte s1, ...
m and s are not part of representation
Unlike in some other languages s known by compiler ? usually irrelevant to programmer m often known by compiler ? if not, must be saved by
programmer
0x1008 0x1004 0x1000
a[2] a[1] a[0]
int a[3];
Cox
Arrays and Pointers
4
Array Representation
char int char int
c1; a[3]; c2; i;
0x1014
0x1010
c2
0x100C
0x1008
0x1004
0x1000
c1
Cox
i
a[2] a[1] a[0]
Arrays and Pointers
Could be optimized by making these adjacent, and reducing padding
(by default, not)
Array aligned by size of elements
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- arrays and pointers in c rice university
- c programming and embedded systems
- ch 10 characters c strings and characters the string class
- lecture 05 arrays and pointers1
- c pointers gdb
- characters and strings
- 261 more array exercises depaul university
- arrays in c
- 6 087 lecture 5 january 15 2010 mit opencourseware
- chapter 16 pointers and arrays
Related searches
- carbs in white rice cooked
- nutrition in white rice cooked
- calories in minute rice white
- calories in white rice dry
- calories in minute rice cooked
- calories in white rice cooked 1 cup
- calories in white rice cup
- calories in brown rice cooked
- calories in brown rice cup
- how many calories in brown rice cup
- carbs in white rice flour
- rice university biology ranking