What does "undeclared identifier" mean?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thistleryver
    New Member
    • Oct 2006
    • 1

    What does "undeclared identifier" mean?

    I thought it meant that I hadn't declared a variable but I have.

    Code:
    int DoubleNumbers(int seq[], int *digitNum)
    {
    	int i, j;
    
    	for (i = 0; i = 9; i++)
    		for (j = i + 1; j = 9; j++)
    			if (seq[i] == seq[j]){
    				*digitNum = j;
    				return 1;
    			}
    	return 0;
    }
    An error message comes up and says that both i and j are "undeclared identifiers". Can anyone help me?
    Last edited by Banfa; Oct 11 '06, 09:33 PM. Reason: Added [code] ... [/code] tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    That code compiles fine for me, no problems, it must be a different bit of your code causeing the error.

    Comment

    • D_C
      Contributor
      • Jun 2006
      • 293

      #3
      Code:
      for (i = 0; i = 9; i++)
      should probably changed to
      Code:
      for (i = 0; i != 9; i++)
      or
      Code:
      for (i = 0; i < 10; i++)
      Similarly for j.

      Comment

      • shaikh riyaz
        New Member
        • Oct 2006
        • 3

        #4
        u'r code , i thing it should be like that
        for(i=0;i<10;i+ +)

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Originally posted by thistleryver
          I thought it meant that I hadn't declared a variable but I have.
          It does which is why I don't think this problem is in this section of code.

          However take note of what everyone else has said or your code will enter an infinite loop.

          Comment

          • euxon
            New Member
            • Feb 2013
            • 1

            #6
            Remember scope for "for"-loops.
            Code:
            int DoubleNumbers(int seq[], int *digitNum) 
            { 
                int i, j; 
              
                for (i = 0; i = 9; i++){ 
                    for (j = i + 1; j = 9; j++){ 
                        if (seq[i] == seq[j]){ 
                            *digitNum = j; 
                            return 1; 
                        }
                     }
                } 
                return 0; 
            }

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              While adding braces in this manor is good practice in this particular instance adding those braces does not actually change the codes functionality.

              Comment

              Working...