From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Comparing arrays and pointers

Comparing arrays and pointers

- [Instructor] 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 ampersand, the address of operator That's because the compiler treats the array like a pointer. It holds an address, the start of the array, which you can prove by running the code, and it works. Individual variables require the address of operator with a scan if function. An array element requires the ampersand, but not an array and not a pointer. To prove how this works, I'm going to add a pointer to the code and I will assign the pointer to the array. Again, the address operator is not required here, and I can prove that the addresses are the same by outputting both. Run the code to see what the addresses are and the addresses are the same, but what about individual elements within the array? In this exercise file, integer array twos contains five elements. Pointer pt is assigned the arrays address at line nine. A for loop…

Contents