Thread: Suffix use

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    73

    Suffix use

    Hello everybody,
    I want to ask: when do i really need to use Suffix for numbers.
    I will give an example:

    let say I write:

    [code]
    long long c;
    [code/]

    the variable c is of long long type. When I want to initiate its value,
    shoule I write:
    [code]
    c = 12;
    [code/]

    when I write it like this, the compiler recognizes that c is a long long type and if I do:
    [code]
    printf("%d",sizeof(c));
    [code/]

    I get the result of 8...which is of course 64 bit. so the compiler actually remembers that c is long long type.

    but I saw some cases (especially in java) that I actually need to force it to be long long by means of c = 12LL, like this next example:

    [code]
    c = 12LL;
    [code/]


    now..I am sure some of you think: why wouldn't I just use a normal int for that purpose, but I have a specific reason that I need to use long long variables.
    Thx.
    Last edited by patishi; 07-14-2014 at 12:42 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You declared the variable c as being a long long, so c is a long long int. The type of c is not dependent on its value. Rather, the range of possible values for c is dependent on the type of c.

    For an integer constant (also called an integer literal), on the other hand, the type is determined by its value (which may be determined by its prefix, if any) and suffix, if any. 12 has no prefix, so it is a decimal constant. It also has no suffix, so it has a type of int since 12 is guaranteed to be in the range of int. 12LL has no prefix, so it is also a decimal constant. It has a suffix of LL, so it has a type of long long int.

    You could safely assign 12 to c because an int can be safely converted to a long long int.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2013
    Posts
    73
    Thx for the reply. so if that so, why do I see sometimes people do: long long board[2];
    n[0] = 0LL;
    n[1] = 0LL;

    what is the purpose of that ?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by patishi
    Thx for the reply. so if that so, why do I see sometimes people do: long long board[2];
    n[0] = 0LL;
    n[1] = 0LL;

    what is the purpose of that ?
    Perhaps they want to be consistent in type and for some reason decided to use assignment instead of initialisation. Nonetheless, in the example you gave, it would be sufficient to write:
    Code:
    long long board[2] = {0};
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Suffix tree help!
    By wuzzo87 in forum C Programming
    Replies: 6
    Last Post: 09-07-2006, 12:03 AM
  2. What does the suffix * mean?
    By flaran in forum C++ Programming
    Replies: 14
    Last Post: 10-18-2005, 09:09 PM
  3. suffix help.
    By milkyway_sushi in forum C++ Programming
    Replies: 1
    Last Post: 11-27-2004, 05:41 PM
  4. suffix trees
    By myjay in forum C++ Programming
    Replies: 1
    Last Post: 11-02-2003, 10:07 PM
  5. Suffix Array
    By bondinc in forum C Programming
    Replies: 1
    Last Post: 10-02-2002, 05:43 PM