By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

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

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

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <conio.h>
  3.  
  4. int main()
  5. {
  6.  const int size= 10;
  7.  double a[size],b[size],c[size],d[size];
  8.  int i,larger;
  9.  
  10.  
  11.  cout<<"Enter your number: "<<endl;
  12.  cin>>a[i];
  13.  cin>>b[i];
  14.  
  15.  for(int i=0; i<10; i++)
  16.  {
  17.   c[i]=a[i]+b[i];
  18.  
  19.   cout<<"  "<<c[i]<<endl;
  20.  }
  21.    if(a[i]>b[i])
  22.       larger=a[i];
  23.   else
  24.       larger=b[i];
  25.  
  26.  
  27.  
  28.   larger=d[i];
  29.   cout<<" "<<d[i]<<endl;
  30.  
  31.   getch();
  32.  }
Dec 31 '15 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
I'm not sure what you mean. Can you give an example from the code you posted?
Dec 31 '15 #2

Expert 100+
P: 2,400
Notice the "enter your number" block of code:
Expand|Select|Wrap|Line Numbers
  1. cout << "Enter your number:" << endl;
  2. cin >> a[i];
  3. cin >> b[i];
This block uses i as an array index before any value has been assigned to it.
Dec 31 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.