primes[0] = 2
primes[1] = 3
primes[2] = 5
if primes is the address of the first element in the array, &primes[0], then *primes is the value that is stored at primes[0], which is 2. the '*' operator dereferences the pointer so you can get the actual value, not the memory address.
the expression *(primes + i) means add i elements to the element primes is pointing to and dereference it, getting the value at the element pointed to by primes + i.
if primes is pointing to the first element, primes[0], then primes+1 = primes[1]. dereference primes[1], *primes, and you get the value 3.
-noix-
In this world gone mad, we won't spank the monkey; the monkey will spank us.
[edited by - noixtirdoe on June 18, 2003 5:09:38 PM]
Why exactly does this code work???
quote:Original post by Tiffany Smith
Maybe im missing something but that code doesnt look like it would work to me because "setw" is not defined and there''s no header file.
cout is in there as well...It can be assumed he''s including iostream and has the line "using namespace std;" (or some equivalent construct)
______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
quote:Original post by blackone
Ravyne, are you sure int Array[100] = {0}; is valid?
Yep
at least in MS VC++ just tested it.
Ravyne
Owner/Lead Programmer & Designer
NYN Interactive Entertainment
HTTP://www.NYNInteractive.cjb.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement