In C we have pointers to return multiple values from a function but how to do it in java?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

In C we have pointers to return multiple values from a function but how to do it in java??

i am learner so please help me

23rd Jun 2017, 11:50 PM
Santosh Kondepudi
Santosh Kondepudi - avatar
4 Answers
+ 1
in c we can return means we can send the values diretly to the adress of required variable.For example take swaping two number program using function
24th Jun 2017, 4:15 AM
Santosh Kondepudi
Santosh Kondepudi - avatar
+ 4
How would you return multiple values with a pointer, even in C? In Java, you return the value: int a = 5; int b = 4; int c = add(a, b); int add(int a, int b){ return a + b; } Java only passes by value with primitive types, so you cannot pass by references with them.
24th Jun 2017, 12:23 AM
Rrestoring faith
Rrestoring faith - avatar
+ 1
vinay lingam it has nothing to do with platform independent nature of java. I have come to know recently. https://www.sololearn.com/discuss/1351579/?ref=app
17th Jun 2018, 10:17 AM
Infinity
Infinity - avatar
0
java was built to avoid pointers, since it was made to become platform independent..
24th Jun 2017, 3:55 AM
vinay lingam
vinay lingam - avatar