From the course: Advanced C Programming: Optimize Performance and Efficiency
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
When to use the ampersand operator - C Tutorial
From the course: Advanced C Programming: Optimize Performance and Efficiency
When to use the ampersand operator
- [Tutor] If you really want to get down and dirty with pointers in C, you need to embrace two unary operators, the ampersand and the asterisk. This movie covers the ampersand. A later movie covers the asterisk. Also of the two, the ampersand causes less trouble although it can be confusing. The ampersand is the address of operator. It returns the memory location of a variable and that's the only way it's used, prefixed to a variable like the engine on a train. The variable doesn't even have to be initialized, just declared. Open exercise 05-01_ampersand1. This code declares four variables, a, b, c and d each of a different type. When a variable is declared it's given a location in memory. To fetch that address, you use the ampersand operator. The printf statement displays those addresses. The %p placeholder is used and the ampersand fetches the address. Build and run this code. The addresses you see on…
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
-
-
-
-
-
-
-
(Locked)
When to use the ampersand operator4m 20s
-
(Locked)
How to bind the asterisk operator4m 51s
-
(Locked)
Challenge: Incrementing a pointer23s
-
(Locked)
Solution: Incrementing a pointer1m 10s
-
(Locked)
Understanding arrays and pointers4m 4s
-
(Locked)
Challenge: Displaying an array29s
-
(Locked)
Solution: Displaying an array54s
-
(Locked)
Obeying the order of precedence6m 27s
-
(Locked)
-