Results 1 to 3 of 3

Thread: literal constants

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Hod Hasharon, Israel
    Posts
    109

    Arrow 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!"

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    The literal constants in are just the numbers (or strings):
    int count = 20;
    float tax_rate = 0.28;
    char *user_name = "John Johnes";

  3. #3
    jim mcnamara
    Guest
    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
  •  



Click Here to Expand Forum to Full Width