Jump to content
Larry Ullman's Book Forums


  • Posts

  • Joined

  • Last visited

Everything posted by michaelzehe

  1. Hello: I was editing on of the scripts from the book and inadvertantly erased the preprocessor #include<string> line and the program worked! This was also true for at least one more programs from the book. MZ
  2. // 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.
  3. 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.
  4. 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
  5. 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
  6. Not to argue with the Guru, but why does including the std:: prefixes make the programming more precise?
  7. 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.
  8. Dear experts: There seems to be a problem with script 8.2 in the C++ book. I can't find any constructors for the subclasses. Also, this script is not present in the downloaded cpp_scripts folder. It skips this one, is it because it has this problem? Thank you. Michael J. Zehe
  • Create New...