Wrox Programmer Forums
|
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 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 June 21st, 2012, 03:14 PM
Authorized User
 
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

given:
  • 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,
drpepper





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





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