Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2008 by Ivor Horton; ISBN: 9780470225905
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2012, 01:48 PM
Authorized User
Points: 57, Level: 1
Points: 57, Level: 1 Points: 57, Level: 1 Points: 57, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Didn't understand ch4:Arrays of pointers

Hi! I don't understand pages 181,182,183.

Especially the section that says:
"Compared to using a ‘normal’ array, the pointer array normally carries less overhead in terms of space. With an array, you would need to make each row the length of the longest string, and six rows of seventeen bytes each is 102 bytes, so by using a pointer array you have saved a whole -1 bytes!"

Why I have saved 1 byte?

Figure 4-7 shows that in the case of the pointer array I am using 103 bytes. I don't understand why 24 bytes are allocated for the pointer array?

In pg. 182 in 3rd paragraph it is mentioned that "With the pointer array as above you just need to swap the pointers". How do I do that?

Thanks
 
Old February 10th, 2012, 08:12 PM
Authorized User
Points: 96, Level: 1
Points: 96, Level: 1 Points: 96, Level: 1 Points: 96, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Posts: 19
Thanks: 0
Thanked 2 Times in 2 Posts
Default

It's -1 byte In the normal array if you set the length of the longest string Hopalong Cassidy\0 17 bytes then each string would be 17 times 6 which is 102 bytes. In the pointer array if you count all the bytes in the strings would be 79. Each pointer would require 4 bytes to hold the address of the string therefore 24 bytes are used by pointers bringing the total byte count to 103.

To swap the pointers just change the names of the pointers
char* pstr1 = "Robert Redford"
char* pstr2 = "Hopalong Cassidy"
change to
char* pstr2 = "Robert Redford"
char* pstr1 = "Hopalong Cassidy"




Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with Ch4 Exercise 3! xiao_mao_mimi BOOK: Ivor Horton's Beginning Java, Java 7 Edition 1 December 22nd, 2011 02:37 PM
Ch4 Problem daivos03 JSP Basics 9 January 30th, 2006 01:57 AM
Pointers and Arrays C++ odie All Other Wrox Books 1 July 10th, 2003 01:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.