|
-
Feb 9th, 2002, 09:18 AM
#1
Thread Starter
Lively Member
literal constants
I hate to ask newbie questions in here, but can someone please
explain to me what is the difference betwenn a literal constant
and a variable??
Here's what my book says
Constants
Like a variable, a constant is a data storage location used by your program. Unlike a variable, the value stored in a constant can't be changed during program execution. C has two types of constants, each with its own specific uses.
Literal Constants
A literal constant is a value that is typed directly into the source code wherever it is needed. Here are two examples:
Int count = 20;
float tax_rate = 0.28;
I see no difference between this and a variable...
"Don't imitate, Innovate!"
-
Feb 9th, 2002, 09:29 AM
#2
The literal constants in are just the numbers (or strings):
int count = 20;
float tax_rate = 0.28;
char *user_name = "John Johnes";
-
Feb 9th, 2002, 09:43 AM
#3
Constants are declared two ways:
Code:
#define BLAH 1 // this is done by the compiler
// it substitutes BLAH for 1
// use:
if (myvar == BLAH){
// do something
}
const int one = 1;
const char *hello = "Hi there";
// these are now constant variables - they cannot be changed
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|