Is there any faster way to write this code?

Discussion in 'C++' started by gwahl, Oct 4, 2010.

  1. gwahl

    gwahl New Member

    Joined:
    Oct 4, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    If I wanted to declare a large number of variables that were all similar, for example:

    var x1;
    var x2;
    var x3;
    var x4;
    var x5;
    var x6;
    var x7;
    var x8;
    var x9;
    var x10;
    var x11;...etc

    Is there a faster way to do that? Maybe something with loops?
     
  2. kranta92

    kranta92 New Member

    Joined:
    Oct 5, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    i don't know what you mean when you say similar...
    if they are the same type (int for example) you can declare an array like this :

    int x[11];

    see this
    learncpp.com/cpp-tutorial/61-arrays-part-i/
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice