Like Tree2Likes
  • 1 Post By laserlight
  • 1 Post By whiteflags

Specifiying Constants L, UL, LL, f

This is a discussion on Specifiying Constants L, UL, LL, f within the C Programming forums, part of the General Programming Boards category; I have looked this up in three books and Google has also failed me. To me a constant is a ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    Specifiying Constants L, UL, LL, f

    I have looked this up in three books and Google has also failed me.

    To me a constant is a value that doesn't not change. It defined by "const", "#define", or a convention of all capital letters to remind the programmer not to change the value.

    What I am seeing is:
    float radius = 0.0f;
    long Big_Number = 1287600L;
    #define PI 3.141f
    circumference = 2.0f*PI*radius;

    Is it keeping the variable type constant? I read that the type can be promoted during implicit conversions.

    IF I guessed correctly, when should it be used?

    If I guessed incorrectly, I am completely lost and don't know when to use it.


    Thank You,
    Carl

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,415
    The variable type is specified in the declaration, e.g., radius is a float because you declared it to be a float. This is true whether or not the variable is declared const.

    The suffix f is used to denote that the floating point literal (constant) is of type float.
    Snaggletooth likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    12
    I don't know if I am over thinking this or if I believe something that is wrong. I think I don't understand was is meant by "constant." The constants I keep finding references to are string constants.

    Is this correct? I have to declare the "variable_name" type and the "value" type seperately.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    Well I don't think there is any harm in thinking the way you do. But to be precise, there are literal constants, which refer to anonymous values. Examples include 5, 'H'; other things that Sesame Street are brought by; and "Hello world!" Even though these things have no name, they have a type. In larger expressions, you might apply a suffix to make sure that the literal is the correct type so that no implicit conversions mess with the result of the calculation (or whatever). Then there are constant variables, which refer to, and qualify, things that you've defined in your program. They usually store literal constants like variables do.
    Snaggletooth likes this.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    12
    I believe I clearly understand now. It seemed redundant so I wanted to be sure I had the right train of thought. The "2.0f" in the expression circumference = 2.0f*PI*radius; makes sense now to.

    Thanks to both of you!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Constants
    By GokhanK in forum C Programming
    Replies: 9
    Last Post: 02-15-2011, 01:01 AM
  2. COnstants
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 09-01-2007, 04:59 AM
  3. Constants
    By shuo in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2007, 11:51 PM
  4. where are the constants?
    By Raven Arkadon in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2005, 01:07 PM
  5. Help with Constants and enum constants. Newbie learning C++.
    By UnregJDiPerla in forum C++ Programming
    Replies: 5
    Last Post: 01-07-2003, 07:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21