Question
1. Let the function fun be defined as (10 pts) fun( int *k) { *k +=4; return 3 * (*k) - 1; } suppose fun
1. Let the function fun be defined as (10 pts)
fun(int *k)
{
*k +=4;
return 3 * (*k) - 1; }
suppose fun is used in the 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. Operands in the expressions are evaluated left to right?
b. Operands in the expressions are evaluated right to left?
2.Consider the following JavaScript Skeletal program (10 pts)
// the main program
var x;
function sub1( ) {
var x;
function sub2( ) {
}
}
function sub3 ( ) {
..
}
Assume that the execution of this program is in the following unit order:
main calls sub1
sub1 calls sub2
sub2 calls sub3
a. Assuming static scoping, in the following, which declaration of x is the correct one for reference to x
i)sub1 ii) sub2 ii) sub 3
b.Repeat part a but assume dynamic scoping.
3. Write a Scheme function get-odd-nums that accepts a list of numbers and returns a new list that contains only the odd numbers. (5 pts)
Example: (get-odd-nums ' (1 2 3 4 5 6 7 8 9 )) should return (9 7 5 3 1)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started