aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes C and java  passing paramter to a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "C and java  passing paramter to a method" Watch "C and java  passing paramter to a method" New topic
Author

C and java passing paramter to a method

Beny Na
Ranch Hand

Joined: May 26, 2004
Posts: 159
Hi..

i just need to confirm is my thinking is correct or not.
java and c use the same concept that when passing a variable into a method is pass by copy(pass a copy of a pointer),because i CAN:T change the pointer to variable int a in this below code.


void test(int *b){
printf("value of b now is %d\n",*b);
printf("address of b(a) is : %d\n ",b);

/* try to change the pointer of variable a */
b = 0;
printf("address of b(a) now is : %d\n ",b);

}

int main(){
int a = 19;
printf("address of a is %d \n",&a);
// pass the address of a
test(&a);

// still pointing to the original address
printf("address of a after trying to change in test() method is %d\n",&a);

}



thanks
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Java always uses "pass by value". C can use either "pass by value" or "pass by reference". For more information, please see this tutorial.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
You can also check out this link.


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: C and java passing paramter to a method
 
Similar Threads
Assign new value to object ref in method
Help with my first Objective-C class
Interesting problem in Java with pass by reference
a confused concept
Problem in running JNI with in servlet