Arrays, Strings, & Pointers - University of Arkansas

Arrays, 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