Arrays, Strings, & Pointers - University of Arkansas

嚜澤rrays, Strings, & Pointers

Alexander Nelson

September 9, 2019

University of Arkansas - Department of Computer Science and Computer Engineering

Arrays, Strings, & Pointers

Arrays, Strings, & Pointers are all connected in C

? Pointer 每 Variable storing a memory location

? Array 每 Block of memory storing associated variables

Array identifier is a pointer to location of first element

? String 每 Array of character variables

1

Example

#include

int main(){

char* myString1 = "Hello!\n";

char myString2[] = "Hello!\n";

printf("%s",myString1);

printf("%s",myString2);

return 0;

}

myString1 and myString2 are equivalent statements!

2

Pointers

Pointers

Pointer 每 Variable that points to a memory location

Requires:

? Name 每 Name of the pointer variable

? Type 每 Type of the variable that is being addressed, with

appended asterisk

e.g. int* myPointer;

Variable size in memory is not based on type, but on memory size

? Why?

3

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download