Share an x variable

  • Thread starter porums
  • Start date
  • #1
27
0

Main Question or Discussion Point

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:
 

Answers and Replies

  • #2
422
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:
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.
 

Related Threads on Share an x variable

  • Last Post
Replies
3
Views
463
  • Last Post
Replies
5
Views
2K
  • Last Post
Replies
9
Views
2K
Replies
11
Views
3K
Replies
11
Views
654
Replies
4
Views
3K
Replies
27
Views
2K
Top