388,113 views
17 votes
17 votes
Why is the following code no good?
int x = 3;
int x = 4;

User Tfogo
by
3.2k points

1 Answer

14 votes
14 votes

Step-by-step explanation:

I don't know what's wrong with your code, because I can't see the whole code.

What happens is that the value 3 is written into the variable x, and later that value is deleted and the value 4 is written in x.

Think of variables as a place in memory to store a value.

Is that C?

User Fabian Giesen
by
2.5k points