Solved Constant intergers vs. intergers?

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

maymonaise

Coder
Meme Tier VIP
Nov 4, 2012
209
943
0
Hey,
I was wondering what the difference is between using a
constant or just a plain variable. I know it's a newb question
but I need to know early on.

C++:
const int ALIEN_POINTS = 150;
vs.
C++:
int alien_points = 150;
 

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
const keyword stands for constant, I see that you've made that clear already.

Now, I suggest you to get a programming book and learn it from the beginning. It has all the answers. :)

With const, you initialize a data variable which you don't have to (you CAN'T) change later on.
Therefore you cannot compare const int with just int.

const comes in handy when you declare something and don't have to change it later on, ie:
C++:
const int fiveHundredDollars = 500
You wouldn't want to accidentally change the value of fiveHundredDollars, would you?
 

-Tek

Newbie
Full Member
Sep 6, 2012
29
324
0
a const can't be changed because it's constant ^^

for exemple if you make a variable with the number of rock in a glass of water (shitty exemple but fuck), you know it won't change, so you declare it as a const
 

maymonaise

Coder
Meme Tier VIP
Nov 4, 2012
209
943
0
a const can't be changed because it's constant ^^

for exemple if you make a variable with the number of rock in a glass of water (shitty exemple but fuck), you know it won't change, so you declare it as a const
const keyword stands for constant, I see that you've made that clear already.

Now, I suggest you to get a programming book and learn it from the beginning. It has all the answers. :)

With const, you initialize a data variable which you don't have to (you CAN'T) change later on.
Therefore you cannot compare const int with just int.

const comes in handy when you declare something and don't have to change it later on, ie:
C++:
const int fiveHundredDollars = 500
You wouldn't want to accidentally change the value of fiveHundredDollars, would you?
Thanks a ton to both of you. By the way, I'm currently
reading Beginning C++ Game Programming by
Michael Dawson. Do you have any other ideas for
books?
 

Syperus

RTFM
Meme Tier VIP
Dank Tier Donator
Oct 29, 2012
432
2,638
7
. Do you have any other ideas for
books?
I can hook you up with some books that helped me along the way. I'm recovering from a computer crash and still restoring all my backups so it'll take some time, but they should help you out. I'll shoot you a pm when i'm done. :)
 

maymonaise

Coder
Meme Tier VIP
Nov 4, 2012
209
943
0
I can hook you up with some books that helped me along the way. I'm recovering from a computer crash and still restoring all my backups so it'll take some time, but they should help you out. I'll shoot you a pm when i'm done. :)
Sounds good, I'll be waiting! Thanks :)
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods