Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Share an x variable

  1. Aug 22, 2008 #1
    I am a novice to computer C programming,
    here the progrm:

    int main()
    {
    int x;
    cin>>x;
    int y1=6*x; //[1]
    int y2=5*x; //[2]
    cout<<y1<<y2;
    }

    which [1] or [2] is evaluated first or equally evaluatd at the same time? :confused:
     
  2. jcsd
  3. Aug 22, 2008 #2
    Firstly, that's C++ code, not C code.

    Secondly, statements are typically evaluated in the order in which they appear. As a result, the statement defining the variable y1 is evaluated before that which defines y2.

    More broadly speaking, if you ever find yourself confused about the evaluation of code, try compiling the code with debugging symbols. You can then step the code through a debugger and watch how each line is evaluated by displaying the variables.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Share an x variable
  1. Static Variables (Replies: 5)

  2. Global variables. (Replies: 7)

Loading...