what does possible use of 'i' before definition in C++?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aza2106
    New Member
    • Dec 2015
    • 1

    what does possible use of 'i' before definition in C++?

    what does possible use of 'i' before definition in C++?

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
     const int size= 10;
     double a[size],b[size],c[size],d[size];
     int i,larger;
    
    
     cout<<"Enter your number: "<<endl;
     cin>>a[i];
     cin>>b[i];
    
     for(int i=0; i<10; i++)
     {
      c[i]=a[i]+b[i];
    
      cout<<"  "<<c[i]<<endl;
     }
       if(a[i]>b[i])
          larger=a[i];
      else
          larger=b[i];
    
    
    
      larger=d[i];
      cout<<" "<<d[i]<<endl;
    
      getch();
     }
    Last edited by zmbd; Jan 1 '16, 02:13 AM. Reason: [z{added code format, included question within post}]
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I'm not sure what you mean. Can you give an example from the code you posted?

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Notice the "enter your number" block of code:
      Code:
      cout << "Enter your number:" << endl;
      cin >> a[i];
      cin >> b[i];
      This block uses i as an array index before any value has been assigned to it.

      Comment

      Working...