michaelzehe
Members-
Posts
11 -
Joined
-
Last visited
michaelzehe's Achievements
Newbie (1/14)
1
Reputation
-
How Many Bytes For An Unsigned Long?
michaelzehe replied to michaelzehe's topic in C++ Programming: Visual QuickStart Guide
Thanks, Antonio. Mike -
How Many Bytes For An Unsigned Long?
michaelzehe replied to michaelzehe's topic in C++ Programming: Visual QuickStart Guide
// address.cpp - Script 6.2 modified #include <iostream> int main() { // Create some variables. unsigned int a = 2; float b = 78.53; char c = 'D'; long d = 1904856026; int e = 9002356; long f=3; std::cout <<"a = "<<a<<std::endl; std::cout <<"b = "<<b<<std::endl; // Print the addresses. std::cout << "The address of a is " << (unsigned long) &a << "\n"; std::cout << "The address of b is " << (unsigned long) &b << "\n"; std::cout << "The address of c is " << (unsigned long) &c << "\n"; std::cout << "The address of d is " << (unsigned long) &d << "\n"; std::cout << "The address of e is " << (unsigned long) &e << "\n"; std::cout << "The address of f is " << (unsigned long) &f << "\n"; const unsigned long I=3; long arr = {100.987,200.876,300.765}; long *A_ptr= arr; for (int i =0; i<I; ++i){ std::cout<<reinterpret_cast<long>(A_ptr)<<std::endl; A_ptr++; } std::cout << "Press Enter or Return to continue.\n"; std::cin.get(); return 0; } // End of the main() function. This gives the following output: a=2 d=1904856026 The address of a is 229536 The address of b is 229532 The address of c is 229531 The address of d is 229524 The address of e is 229520 The address of a is 229516 address for an element of (long) array is 2293504 address for an element of (long) array is 2293508 address for an element of (long) array is 2293512 Press Enter or Continue to continue. This output tells me that the long constant 'D' has a length of 7, but when a long loop was built, its addresses are 4 bytes apart! The unsigned aspect of the problem doesn't come in here. -
How Many Bytes For An Unsigned Long?
michaelzehe replied to michaelzehe's topic in C++ Programming: Visual QuickStart Guide
OK. I meant size, sorry. But the basic question remains: if I print out the addresses for variables of type long (not unsigned long), the number comes out to 7, which isn't even divisible by 2. -
Hello everyone: I am confused about the output from script 6.3. I read it that the integer has a length of 4 bytes, character = 1, float = 4. But the unsigned long gives a value indicating a length of 7. At least to me. Making in a 'non unsigned; long doesn't change things. Making up an array of unsigned longs and printing out their addresses like in script 6.5 gives lengths of 4 bytes, not 7. Does anyone understand this? Thank you. MJZ
-
Maybe There'S A Mistake In Script 8.2
michaelzehe replied to michaelzehe's topic in C++ Programming: Visual QuickStart Guide
I merely failed to see the constructor + deconstructor on lines 31-35 and 65-79, being bleary-eyed after studying this stuff too much. I was also confused because pets.cpp is script 8.1, but pets2.cpp is 8.3, and it seemed that Larry had shifted things somehow. Failing to see that 8.2 was flow.cpp. I told you my brain was smoked!! Mike -
I was reading another C++ book (!) and i saw that they never used those annoying std:: prefixes for strings etc. and I saw they used a statement at the beginning that says: " Using namespace std; " So it tried it on one of the scripts in this book and it seems to work. Is there anything wrong with me putting this into the codes so I can study the flow, etc without the std:: prefixes? Thank you.
-
Maybe There'S A Mistake In Script 8.2
michaelzehe replied to michaelzehe's topic in C++ Programming: Visual QuickStart Guide
cockpit error again, sorry. michael j. zehe