Answer the question
In order to leave comments, you need to log in
Why is the compiler expecting a pointer in my code?
In this code, I got an error: Expression must be of type pointer to object, but is of type "int".
void IzmerenieOsadkov(int arr[], int size1, int size2)
{
for (int i = 0; i < size1; i++)
{
int sum = 0, max = 0, index = 0;
for (int j = 0; j < size2; j++)
{
sum += arr[i][j]; // подчоркнута j и ошибка Выражение должно иметь тип указателя на объект, но имеет тип "int"
}
if (sum > max)
{
max = sum;
index = i;
}
}
Answer the question
In order to leave comments, you need to log in
Function parameter int arr[],
But then you have arr[i][j]
. The compiler tries to take the index j, but there is already a number in front of it. So he tells you "chief, I can take the index from the array (pointer), but here the number is not clear."
You are treating a one-dimensional array as if it were two-dimensional.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question