fork download
  1. #include <stdio.h>
  2.  
  3. void pass_by_value(int value)
  4. {
  5. printf("Entering pass_by_value()\n\nAddress of value = %u\nValue of value = %u\n\n", &value, value);
  6. value = 1;
  7. printf("Address of value = %u\nValue of value = %u\n\nExiting pass_by_value()\n\n", &value, value);
  8. }
  9.  
  10. void pass_by_reference(int *reference)
  11. {
  12. printf("Entering pass_by_reference()\n\nAddress of reference = %u\nValue of reference = %u\nDereferenced value = %u\n\n", &reference, reference, *reference);
  13. *reference = 1;
  14. printf("Address of reference = %u\nValue of reference = %u\nDereferenced value = %u\n\nExiting pass_by_reference()\n\n", &reference, reference, *reference);
  15. }
  16.  
  17. int main(void)
  18. {
  19. int variable = 0;
  20. printf("Address of variable = %u\nValue of variable = %u\n\n", &variable, variable);
  21. pass_by_value(variable);
  22. printf("Address of variable = %u\nValue of variable = %u\n\n", &variable, variable);
  23. pass_by_reference(&variable);
  24. printf("Address of variable = %u\nValue of variable = %u\n\n", &variable, variable);
  25. return 0;
  26. }
Success #stdin #stdout 0.02s 1720KB
stdin
Standard input is empty
stdout
Address of variable = 3216271776
Value of variable = 0

Entering pass_by_value()

Address of value = 3216271744
Value of value = 0

Address of value = 3216271744
Value of value = 1

Exiting pass_by_value()

Address of variable = 3216271776
Value of variable = 0

Entering pass_by_reference()

Address of reference = 3216271744
Value of reference = 3216271776
Dereferenced value = 0

Address of reference = 3216271744
Value of reference = 3216271776
Dereferenced value = 1

Exiting pass_by_reference()

Address of variable = 3216271776
Value of variable = 1