Ok guys im now at lesson 8 (Arrays)
So i took the quiz:
4. Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?
A. foo[6];
B. foo[7];
C. foo(7);
D. foo;
I answered the B,while the correct was A.
Frmoo what i know the only thing we can access "directly" is always the last element(in this case 100)
So why cant i get 7?
Is this a general case?I should remove 1(-1) to get the element i want everytime?
Example:
If i want to access the 10th element,should i put foo[9]; ?
Also:Now reading part 9 (Strings)
So i saw this example:
Code:
#include <iostream>
using namespace std;
int main()
{
char string[256]; // A nice long string
cout<<"Please enter a long string: ";
cin.getline ( string, 256, '\n' ); // Input goes into string
cout<<"Your long string was: "<< string <<endl;
cin.get();
}
Regarding "cin.getline ( string, 256, '\n' );"
i didnt find any actual reason to include the 256 after the string so i maddified it to:
cin.getline ( string,'\n' );
and it worked.
Whats the difference?