By Value and Reference Lesson

The following code is part of our By Value and Reference Lesson:

#include <stdio.h>

int ByVal(int j){
    
    j=j+1;
    
    printf("\n\nByVal(): The Value of j is %08x, the address is %08x\n\n",j,&j);
    
    return(j); 
    
}

int ByRef(int* j){
    *j=*j+1;
    
    printf("\n\nByRef(): The Value of j is %08x, the address is %08x\n\n",*j,j);
    
    return(*j);
}

int main(int argc, char** argv) {
    int rc=0;
    int var=29;
    
    printf("\nmain():  Before Calling any functions var is %08x, the address is %08x\n",var,&var);    
    
    printf("main():  Calling ByVal var=%d\n",var);
    rc=ByVal(var);
    printf("main():  Returned from ByVal var=%d   rc=%d\n",var,rc);
    
    printf("\nmain(): After call to ByVal var is %08x, the address is %08x\n",var,&var);    
    
    
    printf("\n\nmain():  Calling ByRef var=%d\n",var);
    rc=ByRef(&var);
    printf("main():  Returned from ByRef var=%d   rc=%d\n",var,rc);
    
    printf("\nmain(): After call to ByRef var is %08x, the address is %08x\n",var,&var);    

    return 0;
}