Question

b) [3 points] What will be the output of the following code? Explain your answer. enum direction {UP, DOWN, LEFT, RIGHT); voi

0 0
Add a comment Improve this question Transcribed image text
Answer #1
d1 is passed as reference, So changing value with in the function reflects in main.
d2 is passed as value, so changing value with in the function does not reflects in main.

In foo function:
----------------
c is referencing a.
and changing the value of a using reference c with the line "*c = LEFT".
Then reassigning c with b.
But changing the value of b does not reflects in main.

So, after the function call
value of a is LEFT and value of b is DOWN.

So, Output is
d1 = 0, d2 = 1
d1 = 2, d2 = 1

Note: enums starts with 0.
Add a comment
Know the answer?
Add Answer to:
b) [3 points] What will be the output of the following code? Explain your answer. enum...
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
  • please explain very well.Thanks Question 3) What is the output of the following code? (4 marks)...

    please explain very well.Thanks Question 3) What is the output of the following code? (4 marks) #include <stdio.h> int main(void) Output: int i; for (i = 0;i<4; i++) static int a = 0; int b = 0; a++; b++; printf("%d %d", a,b); 11213141

  • What is the output of the following code segment and why? int main(void) { // Find...

    What is the output of the following code segment and why? int main(void) { // Find the output of the following and explain it: char name[] = "Hello"; name[2] = '\0'; printf("%s\n", name); return 0; } why answer is he?

  • /* •   The following code consists of 5 parts. •   Find the errors for each part...

    /* •   The following code consists of 5 parts. •   Find the errors for each part and fix them. •   Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// //////////////        Part A. (5 points)                ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) {       printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// //////////////       ...

  • Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void)...

    Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void) { x = x + 2; y = y + 4; } void bar(void) { int x = 10; y = y + 3; foo( ); cout << x << endl; cout << y << endl; } void baz(void) { int y = 7; bar( ); cout << y << endl; } void main( ) { baz( ); } What output does this program...

  • Assignment: Show the symbol table for the following C programs at the printf lines (a) using lexi...

    Assignment: Show the symbol table for the following C programs at the printf lines (a) using lexical scope and (b) using dynamic scope. What does the program print using each kind of scope rule? Program 1: const int b = 10; int foo() {    int a = b + 10;    return a; } int bar() {    int b = 4;    return foo(); } int main() {    printf(“foo = %d\n”,foo());    printf(“bar = %d\n”,bar());    return 0; } Program 2: int a;                 void...

  • 6) Show the output of the following program. You mus trace the code to show how...

    6) Show the output of the following program. You mus trace the code to show how you reached the answer. (5 points) #include <stdio.h> int x 18; int y = 5; int z ·e; void my first function) void my_second_function); int main() int ys y = x; if (z) my_first functionO else my-second-function(); x++ : if (z) my_first_function(); else my_second_function(); return e; void my_first_function) x+y); is %d\n", printf("The value of x+y in my-first-function() void my_second_function) ( x=100; is %d\n", x);...

  • Problem 4 (25 points). What will the following code print? Why? Identify the line where the...

    Problem 4 (25 points). What will the following code print? Why? Identify the line where the vulnerability is. Explain the vulnerability. Show how the vulnerability can be eliminated Algorithm 2 Example vulnerability l.void called (int foo) 2. if (foo 1) printf("foo") 3. else printf("bar" S.int main O 6. called(2): 7. return 0:)

  • Use the code below to answer the questions that follow. Assume that all proper libraries and...

    Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid , write in the last digit of your SMC student ID. int foo(int a, int b) { //First int c = a+b; while(c>=3) c-=3; return c; } //------------------------------------ char foo(string a, int b) { //Second return a[b]; } //------------------------------------ string foo(int b, string...

  • Given the following code in C, what is the output of this program? (10 Points) int...

    Given the following code in C, what is the output of this program? (10 Points) int mainO f 5. int i=10; for(int j-l;j-3;j++) int i=5 printf("i=%dn', i); printf("f%d\n", i); return 0;

  • 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...

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