AkshaiShah
AkshaiShah

Reputation: 5939

Expected expression before ']' token?

I have the following line which sends the arguments args[] and length to a method called largest.

  printf("Largest is: %d \n", largest(args[], length));

When i try to run this i get the following error:

error: expected expression before ']' token

Upvotes: 0

Views: 24256

Answers (4)

aleroot
aleroot

Reputation: 72636

because you need to place an integer between the operator square brakets, or otherwise don't specify the square brackets :

printf("Largest is: %d \n", largest(&args[0], length));

or

printf("Largest is: %d \n", largest(args, length));

Keep in mind that args[0] is the same as *(args + 0) but args[] will give an error because it needs a number to sum ...

Upvotes: 5

DrummerB
DrummerB

Reputation: 40211

You can't pass an array like that. You have to pass the pointer to the array (first item):

printf("Largest is: %d \n", largest(args, length));

Upvotes: 1

Chris O
Chris O

Reputation: 5037

You probably just want the pointer of the array, so pass in largest(args, length) instead.

Upvotes: 1

Ionut Hulub
Ionut Hulub

Reputation: 6326

 printf("Largest is: %d \n", largest(args, length));

just remove the '[]', because args is a pointer and that's what the function is expecting.

Upvotes: 1

Related Questions