Understanding the Evaluation Order of an X Variable in C Programming

  • Thread starter Thread starter porums
  • Start date Start date
  • Tags Tags
    Variable
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
porums
Messages
27
Reaction score
0
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]
count<<y1<<y2;
}

which [1] or [2] is evaluated first or equally evaluatd at the same time? :confused:
 
Physics news on Phys.org
porums said:
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]
count<<y1<<y2;
}

which [1] or [2] is evaluated first or equally evaluatd at the same time? :confused:

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.