Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 7th, 2010, 9:07 PM   #1
Smjprogrammer
Learning Very Basic Stuff
 
Smjprogrammer's Avatar
 
Join Date: Jan 2010
Location: United States
Posts: 978
Rep Power: 8 Smjprogrammer is on a distinguished road
Arrays in C and C++

http://augustcouncil.com/~tgibson/tutorial/arr.html
__________________
HP Laptop / AMD A4 - 3305 APU with Radeon HD Graphics 1.90 Ghz
Windows 10 64-Bit
Visual Studio Community 2015
Recommended Books - C++ All-In-One For Dummies / Webster's Computer Dictionary
Smjprogrammer is offline   Reply With Quote
Old Dec 30th, 2012, 11:41 AM   #2
modifiable_lvalue
Programmer
 
Join Date: Dec 2012
Posts: 63
Rep Power: 5 modifiable_lvalue is on a distinguished road
Re: Arrays in C and C++

Quote:
Originally Posted by That website
#include <iostream>
int main()
{
   float fl=3.14;
   std::cout << fl << std::endl;
   return 0;
}
#include <stdio.h>
int main()
{
   float fl=3.14;
   printf("%.2f\n", fl);
   return 0;
}
When fl is used in line (5), two distinct steps occur:
1.The program finds and grabs the address reserved for fl--in this example 924.
2.The contents stored at that address are retrieved
To generalize, whenever any variable is accessed, the above two distinct steps occur to retrieve the contents of the variable.
Forgive me for playing the devil's advocate, but that is just silly!
modifiable_lvalue is offline   Reply With Quote
Old Dec 30th, 2012, 4:50 PM   #3
Benoit
Security Specialist
 
Benoit's Avatar
 
Join Date: Sep 2004
Posts: 1,053
Rep Power: 14 Benoit will become famous soon enough
Re: Arrays in C and C++

I wouldn't say it's silly.. Just not really relevant to how we think about arrays in C++. When using single variables theres no notion of addresses and memory retrieval unless using the address-of operator.

The described steps are architecture-specific. The description is close to what would happen on x86: address of the variable would be calculated using the stack pointer and offset, and the value would be retrieved.

But on on PowerPC for example, this would not happen. The value would already be in a register.

EDIT: Also wondering why you're resurrecting a thread from 2010
Benoit is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC