Question

Suppose you were debugging the push() function of your program. Which of the following variables would be accessible to the dreturn malloc(size); void push (void *value) { struct node *n = new_node(); n->value = value; n->next = stack; stack = n; } OWhat would be output of the following code, assuming that normal order evaluation is used? (You may assume all arguments are(define counter (new-count)) (define foo (lambda (x) (+ (- 0x) x x) (display (foo (counter))) 3 4 O2 1 Previous Page Next Pagint foo () { int fun = 0; int bar (int fun) { fun = fun - 1; return fun + 1; return fun + bar (fun - 1); print (foo () ); -1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) 3rd option - stack, node, value and size.

Because, push() is the function which is used to insert or append a new element into the stack. New element is inserted by creating a new node to store the value and after inserting the value or data into the node, stack pointer will move to next address.

Here, before using push(), a new node is created to store the value in stack. Size is allocated dynamically bu using malloc function. So, the variables accessed before using push() are stack,node,value and size.

So, 3rd option is correct.

2) 1st option - 3.

When display (foo(counter)) is called, the counter value is obtained from the definition counter(new-count). Here, counter(new-count) holds the value obtained from new-count(lambda()). Initially, cnt is 0 and incremented if the condition is true. So, cnt value increase for 3 times. Hence, cnt hold value of 3. This value is finally returned to foo(counter). Hence display () function gives output as 3.

3) 1st option - (-1).

When print() is called, foo() is called. Now, fun is 0. Then, this foo() function holds the value fun+bar(fun-1), i.e foo() holds 0(+bar-1). Where, bar(-1) holds the value fun+1. Where, fun is -2. So, bar(-1) holds -1. Finally print (foo()) display output as -1.

Comment if u have any doubt.

Thank you.

Add a comment
Know the answer?
Add Answer to:
Suppose you were debugging the push() function of your program. Which of the following variables would...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 5 (1 point) Suppose you were debugging the following C code. Which of the following...

    Question 5 (1 point) Suppose you were debugging the following C code. Which of the following variables would be accessible to the debugger when the call to push() complete? static struct node *stack; static struct node *new_node() { int size = sizeof(struct node); return malloc(size); بب void push (void *value) { void push (void *value) { struct node *n = new_node(); n->value = value; n->next = stack; stack = n; } stack, value. n, size stack stack, n, value stack,...

  • Need help. write a C program stack-ptr.c that implements a stack using a link list. Below...

    Need help. write a C program stack-ptr.c that implements a stack using a link list. Below is a skeleton code to start with.Jjust edit to make thread friendly. examplpe: push(5, &top); push(10, &top); push(15, &top); int value = pop(&top); value = pop(&top); value = pop(&top); this program currently has a race condition. use Pthread mutex locks to fix the race conditions. test you now thread safe stack by creating 200 concurrent threads in main() that push and pop values. -use...

  • Question 4 (1 point) Consider the following piece of C code. What can be said about...

    Question 4 (1 point) Consider the following piece of C code. What can be said about the pop() function in this piece of code only? struct node { struct node *next; void *value; }; static struct node *stack; void * pop() { void * value = stack->value; void * pop() { void * value = stack->value; free (stack); stack = stack->next; return value; } void push (void *value) { struct node *node = malloc(sizeof(struct node)); node->value = value; node->next =...

  • Using C, I need help debugging this program. I have a few error messages that I'm...

    Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...

  • My Output s1 (size 0): s1 is empty Testing push() s1 (size 1): 17 s1 is...

    My Output s1 (size 0): s1 is empty Testing push() s1 (size 1): 17 s1 is not empty s1 (size 4): 4 6 2 17 s1 is not empty Testing copy constructor s1 (size 4): 4 6 2 17 s2 (size 4): 4 6 2 17 Testing clear() s1 (size 0): s2 (size 4): 0 1477251200 1477251168 1477251136 s3 (size 4): 28 75 41 36 Testing assignment operator s3 (size 4): 28 75 41 36 s4 (size 4): 28 75...

  • Hi, I need to make a program in C that reads the type of currency and...

    Hi, I need to make a program in C that reads the type of currency and organizes them into stacks based on currency which can be read back. This is what I have so far, can I get help finishing it? #include <stdio.h> #include <stdlib.h> const float POUND = 1.31; const float YEN = 0.0091; const float RUPEE = 0.014; const float EURO = 1.11; char c; int currValue; float exchangeValue; float finValue; int printValue; struct node {    int...

  • I need help on this Systems review please! it's due by midnight monday. Question 1 Not...

    I need help on this Systems review please! it's due by midnight monday. Question 1 Not yet answered Points out of 1.00 Flag question Question text Using these declarations: int * numberPointers[3]; int * pointer; int number; Which of the following statements would generate a warning or error? Select one: a. number = pointer; b. *pointer = number; c. pointer = numberPointers; d. numberPointers[2] = &number; e. a., b., and d. f. a. and c. Question 2 Not yet answered...

  • 1. static int function(int n){ return n * function(n + 1); } If you call the...

    1. static int function(int n){ return n * function(n + 1); } If you call the method function(2), the expected output is 3. True False 2. public void push(int new_data) { Node new_Node = new Node(new_data); new_Node.next = head; new_Node.prev = null; if (head != null) head.prev = new_Node; head = new_Node; } The code snippet depicts stack implementation True False 3. A ________ list is a linked data structure that consists of a set of sequentially linked records called...

  • Modify the below code to fit the above requirements: struct node { char data; struct node...

    Modify the below code to fit the above requirements: struct node { char data; struct node *next; struct node *previous; } *front, *MyNode, *rear, *MyPointer, *anchor *Valuenode ; typedef struct node node; int Push(char input) { if(IsFull()==1) {   printf("The queue is full. Enter the ‘^’ character to stop.\n"); return -1; } else if (IsFull()==-1) { node *MyNode=(node*)malloc(sizeof(node)); MyNode->data=input; rear->next=MyNode; MyNode->previous=rear; MyPointer=rear=MyNode; return 1; } else { node *MyNode=(node*)malloc(sizeof(node)); node *anchor=(node*)malloc(sizeof(node)); MyNode->data=input; MyPointer=rear=front=MyNode; MyNode->previous=NULL; MyNode->next=NULL; anchor->next=MyNode; return 0; } } char...

  • Am Specification For this assignment, you will write a multi-file C program to define, implement ...

    Must be written and C, and compile with MinGW. Thank you! am Specification For this assignment, you will write a multi-file C program to define, implement and use a dynamic linked lists. Please refer to Lab 07 for the definition of a basic linked list. In this assignment you will need to use the basic ideas of a node and of a linked list of nodes to implement a suit of functions which can be used to create and maintain...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT