Why isn't the address of the array itself the same as the address of the first element in an array when the array is passed as an parameter to a C function?
-
Let's say I have a function defined as void f(int a[]) and an array defined as int b[] = {1,2,3}. In function f, I print the address of a and the address of a[0], but find out that they are not the same. Why would this happen?
-
Answer:
Your function doesn't really take in an array, but rather a pointer to an int. The address of a is the address of that pointer (local to your function); the address of a[0] is within the array and is in fact the same as the value of a.
Jelle Zijlstra at Quora Visit the source
Related Q & A:
- Why Isn't Montgomery Modular Exponentiation Considered For Use In Quantum Factoring?Best solution by cstheory.stackexchange.com
- Why isn't a webcam working with AIM?
- Why isn't a new tab opened any longer?Best solution by Ask.Metafilter.Com
- Why doesn't my address book appear when I forward mail?Best solution by Yahoo! Answers
- If the "blackbox" flight recorder is never damaged during a plane crash, why isn't the whole damn airplane mad?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.