first off I have an array of classes with 50 elements i pass them to a function using a * instead of []'s. When I incriment my pointer do i need to incriment by sizeof(class) or 1?
first off I have an array of classes with 50 elements i pass them to a function using a * instead of []'s. When I incriment my pointer do i need to incriment by sizeof(class) or 1?
>> When I incriment my pointer do i need to incriment by sizeof(class) or 1?
by one; the compiler automatically calculates the correct byte offset given the pointer type.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
You can just use
In most situations, the ++ operator just adds 1, but since you are working with a pointer, the compiler will automatically increment the memory address contained in your pointer by the right amount (nice feature).Code:pointername++;
Hmm... Kind of reminds me of one of those stupid pet tricks you can do with pointers (namely, the addition of pointers using the subscript notation):
Code:#include <iostream> int main() { int t[4] = { 7, 3, 4, 8 }; for(int i = 0; i != 4; ++i) std::cout << i[t] << std::endl; return 0; }
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Yeah, because when you do subscripting you can write it out in its pointer form.
is the same asCode:int array[6]; ... std::cout << array[5] << std::endl;
Since addition is commutative, you can rewrite that asCode:int array[6]; ... std::cout << *(array + (5*sizeof(int))) << std::endl;
which would beCode:int array[6]; ... std::cout << *((5*sizeof(int)) + array) << std::endl;
Very weird. When I first saw that I was like, "wtf?"Code:int array[6]; ... std::cout << 5[array] << std::endl;
Yeah, thats the explanation that I summed up in my cryptic little parenthetical above.
It still just looks weird. "Yes, give me the arrayth element of 5, please..."
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.