Thread: Error " i " undeclared...

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    52

    Error " i " undeclared...

    Code:
    #include<stdio.h>
    
    
    main()
    
    
    {
        for ( i = 0; i < 10; i++)
    {
    printf("%d", i);
    if ( i == 4);
    {
    
    
    break;
    }
    
    
    return 0;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }
    }

    Error message: error: 'i' undeclared (first use in this function)|

    Anything?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,291
    Yeah, you forgot to declare the variable named i.
    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
    Dec 2019
    Posts
    52

    i = o
    Would be suffice?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,291
    No, a declaration of a variable includes its type. So:
    Code:
    int i = 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

  5. #5
    Registered User
    Join Date
    Dec 2019
    Posts
    52
    Ok. Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error expected identifer or "(" beore " . " token
    By cooper1200 in forum C Programming
    Replies: 8
    Last Post: 05-11-2019, 11:35 AM
  2. "File" undeclared issue/stdio not found
    By drewtoby in forum C Programming
    Replies: 6
    Last Post: 05-15-2011, 10:52 AM
  3. "undeclared identifier" error
    By ExDHaos in forum C++ Programming
    Replies: 4
    Last Post: 05-22-2009, 04:10 PM
  4. Getting "undeclared member" error with derived class
    By indigo0086 in forum C++ Programming
    Replies: 4
    Last Post: 10-07-2007, 06:41 AM
  5. Replies: 1
    Last Post: 08-06-2007, 10:09 PM

Tags for this Thread