Prog Book Error

This is a discussion on Prog Book Error within the C++ Programming forums, part of the General Programming Boards category; Can anyone see why this code produces letters and numbers and not the numbers 0 - 14? I think the ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479

    Prog Book Error

    Can anyone see why this code produces letters and numbers and not the numbers 0 - 14? I think the author made a typo somwhere. It is suposed to be a shorter version that having to use a for loop to literate through the array elements. I get no errors or warnings.

    Code:
    #include <iostream>
    
    using std::cout;	
    using std::endl;
    
    // main function - where program execution begins
    int _tmain(int argc, _TCHAR* argv[])
    {
    	const int ArraySize = 15;
    
    	int n[ ArraySize ] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
    
    	cout << "My array: " << n << " ";
    
    	getchar();	// need to freeze output in debug mode
    
    	return 0;	// indicates program ended sucsessfully
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    that only displays the address of the array, not the individual array elements. Suggest you go to the publisher's web site and see if there are corrections to that book -- most publishers have them free for the downloading.

    and I wouldn't trust any book that attempts to teach c++ and winds up using C functions such as getchar()! That alone tells me the book isn't worth the paper its printed on.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >It is suposed to be a shorter version that having to use a for loop to literate through the array elements.
    Either that's not the complete code in the book, or the author doesn't know C++ well enough to teach it. Then again, if there is more code that allows you to print an array like this, I would argue that the author still doesn't know C++ well enough to teach it properly.

    The code suggests fundamental misunderstandings on the author's part.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 02:17 AM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  3. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21