Computer Science Homework Solutions
Problem
#189600

Basic - functions

Please see the attached file.

1.  
Let the function fun be defined as
Int fun(int *k)  {
*k +=4;
Return 3 * (*k) -1;
}
Suppose fun is used in a program as follows:
Void main() {
   Int i = 10, j = 10, sum1, sum2;
   Sum1 = (i/2) + fun(&i);
   Sum2 = fun(&j) + (j/2);
What are the values of sum1 and sum2
a.  if the operands in the expressions are evaluated left to right?
b.  if the operands in the expressions are evaluated right to left?
2.
Consider the following C program:
Int fun(int *i)  {
  *i+= 5;
  Return 4;
}
Void main()  {
  Int x = 3;
  X = x + fun(&x);
}
What is the value of x after the assignment statement in main, assuming
a.  operands are evaluated left to right.
b.  operands are evaluated right to left.

Attached file(s):
Attachments
rework1.docx  View File

Solution Summary

Using pointers in C++ functions to understand how to pass parameters by value and by reference.

Solution
What is this?
By OTA - Overall OTA Rating
Yanfang Li, PhD - 4.9/5
Purchase Cost Now
$2.19 CAD (was ~$11.97)
Included in Download
  • Plain text response
  • Attached file(s):
    • 1_answer.doc
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • Semantics and Runtime Environment - What is the difference between using a pass by value and pass by reference with a compiler?
  • C programming: parameter passing - Need a C program that has a declaration in main () to store the following numbers into an array named rates:2.3,3.3,4.4,5.5,6.0. There should be a function call to show () that accepts rates in a para ...
  • Data Structures with C++ Using STL - Write a function template void stackClear (stack& s); that clears a stack s. Why is it critical that s be passed by reference? Please provide a complete program if it makes s ...
  • Binary Trees C++ - Write the definition of the function leavesCount that takes as a parameter a pointer to the root node of a binary tree and returns the number of leaves in a binary tree. Add this function to the class ...
  • Question - What is exactly a pointer in C? What is the significance of a NULL pointer?
Browse