1

When I want to implement a function in C++ , if it matters to receive the int array in the following cases?

void fn1(int []a) {
  a[0] = 1;
}

void fn2(int a[]) {
  a[0] = 1;
}
remo
  • 870
  • 2
  • 12
  • 30

3 Answers3

10

In Java, there is no semantic difference.

In C++, the first syntax is invalid.

NPE
  • 464,258
  • 100
  • 912
  • 987
2

Well, the question is not clear.. Whether to receive the int array or not, it depends on the logics of your method. In Java it is better to write a[], but you can write either way.

Also, look over here - pass array to method Java

Community
  • 1
  • 1
user
  • 3,000
  • 22
  • 45
2

In Java,the declaration is same... but in C++,the fn1() declaration need to be different