I want to type in two numbers but why doesn this work? I'm confused
int main (void) {
int x[1];
int n;
for( n=0 ; n<2 ; n++) {
scanf("%d", &x[n]);
}
for( n=0 ; n<2 ; n++) {
printf("%d", x[n]);
}
return(0);
}
>>58248442
Should beint x[2];
>>58248474
but the first number is stored in x[0] and the second in x[1] ?
>>58248493
But if you define x as int x[1] x will only have one space.
>>58248493int x[2];
Here, [2] specifies how many elements there are, not which element is the maximum. So doing x[n] gives you n elements, that is x[0], x[1], x[2], ..., up to x[n-1].
>>58248559
thanks it makes sense now
>>58248574
You just have to realise the difference between declaration ("type_name variable_name[size]") and usage. In declaration, [n] means that you want an array with n elements. In usage, [n] means you want to access element n.