Thread: how many number of character many be in a variable name?

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    9

    how many number of character many be in a variable name?

    hi all,
    I have just started studying C and have gone up to variables.

    by the way, how many number of characters may be in an Identifier?

    I didn't find this anywhere, in a tutorial it is written that C Identifiers may be as long as we like but only the first 31 characters are significant.

    is it true?

    I am using DevC++ IDE in windows xp plateform.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    The 1999 edition of the C standard states that "there is no specific limit on the maximum length of an identifier". Generally, I would say that you should not be worrying about this. Rather, worry about whether you are using appropriate and sufficiently descriptive names.
    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
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    31 is the guaranteed minimum in C89.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User Cooloorful's Avatar
    Join Date
    Feb 2009
    Posts
    59
    I some C compilers of yester-year allow any number of characters to be used for variables but as far as the compiler was concerned only x number of characters were taken into account. So taking what Salem just said into account, C89 compliant compilers may allow you to have a variable with 102 characters in its name in use, but the compiler may only allow a maximum of 31 characters to be used to differenciate which variable is which. I would imagine when you start using variables with terribly similar names you also run the risk of your programs being difficult for the designer to maintain, not just something unmanageable for the compiler to understand.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf with variable number of entries
    By cfdprogrammer in forum C Programming
    Replies: 5
    Last Post: 04-20-2009, 02:02 AM
  2. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  4. Edit a character string with an assigned variable
    By jeffdavis_99 in forum C++ Programming
    Replies: 2
    Last Post: 03-25-2005, 10:54 AM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM