From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Comparing arrays and pointers - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Comparing arrays and pointers
- [Instructor] It's often been said that array notation is a shortcut for pointers which isn't true. You cannot fully substitute what a pointer does by using array notation instead. In this exercise file, text is a 10 element character array. String input is fetched at line eight, but see how the text variable lacks the address of operator? That's because the compiler treats the array like a pointer. It holds an address, the start of the array. Let's build and run. Type something short, hello. Individual variables require the address of operator when used with the scanf function. Even an array element requires the ampersand but not an array and not a pointer. This exercise file displays the address of the text array and the pointer assigned to that address. Build and run. And they're the same, but what about array elements? In this exercise file, an integer array twos contains five elements and pointer pt is assigned that array's address at line nine. A for loop marches through all…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Understanding pointers3m 19s
-
Using pointers to manipulate data2m 28s
-
Doing pointer math2m 57s
-
Comparing arrays and pointers3m 55s
-
Allocating storage3m 15s
-
Working with a pointer array3m 38s
-
Using pointers in structures3m 30s
-
Passing pointers to functions2m 57s
-
Returning pointers2m 39s
-
Challenge: Create a pointer array54s
-
Solution: Create a pointer array2m 23s
-
-
-
-