104k views
4 votes
Why is the following code no good?
int x = 3;
int x = 4;

User SinDizzy
by
7.7k points

1 Answer

4 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 Pablo Martinez
by
7.2k points