Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Ivor Horton's Beginning Visual C++ 2010
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2010 by Ivor Horton; ISBN: 9780470500880
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2010 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 21st, 2012, 03:14 PM
Authorized User
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: May 2012
Posts: 66
Thanks: 0
Thanked 4 Times in 4 Posts
Default C++ variable initialization

I am posing questions to prevent becoming trapped by making incorrect assumptions. That could bite me later.

There is a similarity in the general format of:
  • int num; to declare a variable
  • int num = 0; to initialize a variable
  • int num(0); to initialize a variable
  • return_type function_name(parameter) function header
  • type function_name (parameter); function prototype

  • int num = 0; and int num(0); are equivalent
  • Using int num(0) can present confusion because:
    1. type function_name(parameter) can be identical to a function prototype.
    2. The absence of a semicolon is the only visible difference between a function header and int num(0);
In real life programming, is it a good idea to avoid int num(0) to avoid confusion?
Is the physical location of the statement coupled with the context with which it is presented always clear enough to distinguish the difference?

Thanks for your replies,

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding String Initialization chris@p2p Java Basics 3 April 25th, 2009 01:58 PM
Declaration of variable without initialization v_kewlani Other Programming Languages 0 May 24th, 2007 01:51 AM
variable initialization vin_0x1 Classic ASP Databases 1 April 18th, 2006 06:46 AM
initialization vin_0x1 Classic ASP Professional 3 April 16th, 2006 06:40 AM
variable initialization with try..finally guppyheart C# 7 July 17th, 2003 06:47 AM

All times are GMT -4. The time now is 09:13 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.