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 - C Tutorial
From the course: Complete Guide to C Programming Foundations
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
-
-
-
-
-
-
-
-
-
-
Understanding pointers3m 23s
-
(Locked)
Using pointers to manipulate data2m 53s
-
(Locked)
Doing pointer math3m 10s
-
(Locked)
Comparing arrays and pointers5m 5s
-
(Locked)
Challenge: Output a string57s
-
(Locked)
Solution: Output a string2m 44s
-
(Locked)
Allocating storage3m 42s
-
(Locked)
Working with a pointer array4m
-
(Locked)
Using pointers in structures3m 8s
-
(Locked)
Challenge: Allocating structures1m 3s
-
(Locked)
Solution: Allocating structures3m 34s
-
(Locked)
Passing pointers to functions2m 23s
-
(Locked)
Returning pointers from a function2m 31s
-
Chapter challenge: Processing input1m 26s
-
(Locked)
Chapter solution: Processing input3m 14s
-
-
-
-