Welcome to our forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Forum Statistics

  • Forum Members:
  • Total Threads:
  • Total Posts: 5
There are 1 users currently browsing forums.
C and C++ Programming C and C++ are both robust and hugely popular programming languages that are used in multiple facets of programming, ranging from games to operating systems to simple text editors. To dicuss and seek advice, ask around here.

Reply
  #1  
Old 07-03-2009
hashimi's Avatar
Teenager
 
Join Date: Nov 2006
Location: Kabul
Posts: 152
Rep Power: 4
hashimi is on a distinguished road
Memory address of the first element

I was solving a quiz and this is a question:

Which of the following gives the memory address of the first element in array foo, an array with 100 elements?

A. foo[0];
B. foo;
C. &foo;
D. foo[1];


Both foo and &foo gives the same result. Which one is true?

Thanks
Reply With Quote
  #2  
Old 07-04-2009
hashimi's Avatar
Teenager
 
Join Date: Nov 2006
Location: Kabul
Posts: 152
Rep Power: 4
hashimi is on a distinguished road
Re: Memory address of the first element

No answer??
Reply With Quote
  #3  
Old 07-06-2009
I'm cacographic!
 
Join Date: Apr 2006
Location: Texas, USA
Age: 17
Posts: 1,662
Rep Power: 5
ddreier is on a distinguished road
Re: Memory address of the first element

I'm not sure what you mean by the memory address, but '0' is always the first element in an array of any size
Reply With Quote
  #4  
Old 07-19-2009
Toddler
 
Join Date: Jul 2009
Posts: 6
Rep Power: 0
Chinmay is on a distinguished road
Re: Memory address of the first element

I'm not sure but i think it is &foo becaz it will point to memory location of first element of array i.e. foo[0]
Reply With Quote
  #5  
Old 07-19-2009
gorda001's Avatar
This user is deprecated.
 
Join Date: Jun 2005
Location: <0x79a3f6>
Posts: 5,064
Rep Power: 10
gorda001 is on a distinguished road
Re: Memory address of the first element

Just plain foo.

The first element of the array is foo[0]. Indexing is, in pointer arithmetic:
foo[n] := *(foo+n)

So therefore the memory address of the first element is &(*(foo+0)) or foo.
Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory Manager Based on buckets of fixed-size memory blocks raghuu1234 C and C++ Programming 5 11-06-2008 04:20 AM
How to prevent Firefox from consuming too much memory Relinquished Articles, Tutorials, and Guides 8 04-29-2007 07:55 AM
[Tutorial] Fix Firefox memory leaks sirjavabean Articles, Tutorials, and Guides 6 09-14-2006 10:12 AM
Spamming Myself NuWeb Chit Chat and Hangout 0 08-14-2006 11:47 AM