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
  • 880
  • 2
  • 14
  • 32

3 Answers3

10

In Java, there is no semantic difference.

In C++, the first syntax is invalid.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
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,058
  • 23
  • 45
2

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