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

Comparing arrays and pointers - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

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…

Contents