Simple Question

This is a discussion on Simple Question within the C++ Programming forums, part of the General Programming Boards category; I think it's a basic question, but I canīt find the answer anywhere. What's the difference between: int x(5); and ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    4

    Simple Question

    I think it's a basic question, but I canīt find the answer anywhere.
    What's the difference between:
    int x(5);
    and
    int x=5;

    Thanks.

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Where did you find int x(5)? int x=5 is a definition where x is initialized to 5.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,101
    Quote Originally Posted by AndresF
    What's the difference between:
    int x(5);
    and
    int x=5;
    The former demonstrates direct initialisation while the latter demonstrates copy initialisation. For objects of built-in types, there is effectively no difference, but for objects of class types copy initialisation would not be allowed if the respective constructor is declared explicit.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    4
    Thank you very much, thatīs just what I wanted to know

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 09:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2005, 12:41 AM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM

Tags for this Thread


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