Question

1 Assume that the address of b[0] is 5206 in memory. What output would be produced by the following program (if the output is an address, you need to write out the exact address. For example, the address of b[1] is 5210)? #include <iostream> using std::cout; using std::endl; int main() { int b[] = {3,4,2,5,6,7}; int *xPtr; xPtr = &b[3]; cout << xPtr << endl; cout << *xPtr << endl; cout << &b[4] << endl; cout << b[5] << endl; *xPtr = 9; cout << *xPtr << endl; return 0; } void leftshift (int *array) { int temp = *array; for (int i = 0; i < 9; i++) *(array+i) = *(array+i+1); *(array+9) = temp; for (int i = 0; i<10; i++) cout << *(array+i) << " "; cout << endl; }

          1 Assume that the address of b[0] is 5206 in memory. What output would be
produced by the following program (if the output is an address, you need to
write out the exact address. For example, the address of b[1] is 5210)?
#include <iostream>
using std::cout;
using std::endl;
int main()
{
int b[] = {3,4,2,5,6,7};
int *xPtr;
xPtr = &b[3];
cout << xPtr << endl;
cout << *xPtr << endl;
cout << &b[4] << endl;
cout << b[5] << endl;
*xPtr = 9;
cout << *xPtr << endl;
return 0;
}
void leftshift (int *array)
{
int temp = *array;
for (int i = 0; i < 9; i++)
*(array+i) = *(array+i+1);
*(array+9) = temp;
for (int i = 0; i<10; i++)
cout << *(array+i) << " ";
cout << endl;
}
        
Show more…
1 Assume that the address of b[0] is 5206 in memory. What output would be
produced by the following program (if the output is an address, you need to
write out the exact address. For example, the address of b[1] is 5210)?
#include <iostream>
using std::cout;
using std::endl;
int main()

int b[] = 3,4,2,5,6,7;
int *xPtr;
xPtr =    b[3];
cout << xPtr << endl;
cout << *xPtr << endl;
cout <<    b[4] << endl;
cout << b[5] << endl;
*xPtr = 9;
cout << *xPtr << endl;
return 0;

void leftshift (int *array)

int temp = *array;
for (int i = 0; i < 9; i++)
*(array+i) = *(array+i+1);
*(array+9) = temp;
for (int i = 0; i<10; i++)
cout << *(array+i) << " ";
cout << endl;

Added by Alexander P.

Close

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
1. The include statement should be corrected to: #include <iostream> 2. The using statements should be corrected to: using std::cout; using std::endl; 3. The main function declaration should be corrected to: int main() 4. The array initialization should use commas instead of periods: int b[] = {3, 4, 2, 5, 6, 7}; 5. The pointer declaration should use a semicolon instead of a colon: int *xPtr; 6. The for loop syntax is incorrect and should be corrected to: for (int i = 0; i < 9; i++) 7. The shift operator should be corrected to: << instead of ≪ 8. The square root symbol should be corrected to: ** 9. The return statement should be at the end of the main function. 10. The void leftshift function is not used in the provided code and can be removed.
Close icon
Play audio
Feedback
Powered by NumerAI
Danielle Fairburn David Collins
Kathleen Carty verified

Akash M and 80 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
c-pointers-and-references-explain-each-c-instruction-use-drawing-of-the-memory-cells-to-explain-int-a-a27-int-ptr-ptr-a-address-operator-reference-cout-ptr-ptr-endl-cout-ptr-ptr-endl-cout-pt-89417

C++ Pointers and References Explain each C++ instruction. Use a drawing of the memory cells to explain. int a; a = 27; int* ptr; ptr = &a; // & address operator – reference cout << "*ptr " << (*ptr) << endl; cout << "ptr " << ptr << endl; cout << "&ptr " << &ptr << endl; cout << "&a " << &a << endl;

Akash M.

q-compute-the-physical-address-for-the-specified-operand-in-each-of-the-following-instructions-the-register-contents-and-variable-are-as-follows-cs-oaooh-ds-obooh-ss-odooh-si-offoh-diooboh-b-41067

'Q: Compute the physical address for the specified operand in each of the following instructions The register contents and variable are as follows: (CS)-OAOOH, (DS)-OBOOH, (SS)-ODOOH (Si)-OFFOH, (DI)=OOBOH, (BP)-OOEAH and (IP)-OOOOH, LIST-OOFOH, AX-4020H, BX-2SOOH: 1) Destination operand of the instruction MOV LIST [BP+DI] , AX 2) Source operand of the instruction MOV CL , [BX+2OOH] 3) Destination operand of the instruction MOV [Dl+6400H] , DX 4) Source operand of the instruction MOV AL, [BP+SI-4OOH] 5) Destination operand of the instruction MOV [Dl+SP] AX 6) Source operand of the instruction MOV CL , [SP+ZOOH] 7) Destination operand of the instruction MOv [BX+Dl+6400H] CX 8) Source operand of the instruction MOV AL , [BP- O2O0H] 9) Destination operand of the instruction MOv [SI] , AX 10) Destination operand of the instruction MOV [BXJ[DI]+O4OOH,AL 11) Source operand of the instruction MOV AX, [BP+ZOOH] 12) Source operand of the instruction MOV AL, [SI-O1OOH] 13) Destination operand of the instruction MOV DI; [SI] 14) Destination operand of the instruction MOV [DI]+CFOOH,AH 15) Source operand of the instruction MOV CL, LIST[BX+ZOOH]'

Sri K.

iour-iob-is-to-show-hat-the-stacks-will-look-like-after-svap-returns-in-each-of-the-two-programs-program4-iou-need-to-fill-in-the-yellov-boxes-if-they-are-blank-and-update-the-yellow-boxes-i-83045

Your job is to show what the stack's will look like after swap() returns in each of the two programs: program4 You need to fill in the yellow boxes if they are blank and update the yellow boxes if they need adjustment LC4's Data Memory (Stack for Program 4a) Address Contents Description x7FF5 local variable in swap x7FF6 caller's frame pointer x7FF7 caller's return address x7FF8 argument to swap() x7FF9 argument to swap() x7FFA 10 b - local variable in main x7FFB 5 a - local variable in main x7FFC x0000 caller's frame pointer x7FFD x0005 caller's return address x7FFE X main()'s return value x7FFF X arguments to main LC4's Data Memory (Stack for Program 4b) Address Contents Description x7FF5 local variable in swap x7FF6 caller's frame pointer x7FF7 caller's return address x7FF8 argument to swap() x7FF9 argument to swap() x7FFA 10 b - local variable in main x7FFB 5 a - local variable in main x7FFC x0000 caller's frame pointer x7FFD x0005 caller's return address x7FFE X main()'s return value x7FFF X arguments to main In both cases, the values of R5, R6, and R7 - right after the JSR() to swap() occurs - but before the prologue of swap() occurs : R5 = x7FFC R6 = x7FF8 R7 = x0075 10 #include <stdio.h> 11 void swap (int a, int b) { 12 int c = 0 ; 13 c = a ; /* swap values of a and b */ 14 a = b ; 15 b = c ; 16 printf ("a= %d ", a) ; 17 printf ("b= %d ", b) ; 18 return ; 19 } 20 int main() { 21 int a = 5 ; 22 int b = 10 ; 23 printf ("a= %d ", a) ; 24 printf ("b= %d ", b) ; 25 swap (a, b) ; 26 printf ("a= %d ", a) ; 27 printf ("b= %d ", b) ; 28 return (0) ; 29 } 10 #include <stdio.h> 11 void swap (int* a, int* b) { 12 int c = 0 ; 13 c = *a ; /* swap values of a and b */ 14 *a = *b ; 15 *b = c ; 16 printf ("a= %d ", *a) ; 17 printf ("b= %d ", *b) ; 18 return ; 19 } 20 int main() { 21 int a = 5 ; 22 int b = 10 ; 23 printf ("a= %d ", a) ; 24 printf ("b= %d ", b) ; 25 swap (&a, &b) ; 26 printf ("a= %d ", a) ; 27 printf ("b= %d ", b) ; 28 return (0) ; 29 }

Akash M.


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,629 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,888 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,377 solutions

*

Transcript

-
00:01 So as it is given in the question int a then a is equals to 27 then int star ptr ptr is equals to ampersand a then cout star ptr the value of star ptr and n again cout that is ptr and it will give ptr the value of ptr and n again cout and ptr and ptr and l and the last cout cout and a and a n so let's understand this with the help of an example int a so a is allocated a memory suppose this is a memory allocated and suppose the address of this variable a is 2022 next in next line when a is equals to 27 this a is given the value as 27 now int star ptr so int star ptr that means ptr is a pointer that is pointing to a variable consisting of an integer value so a ptr will be given suppose now this is ptr and this has addresses 7 4 0 4 6 next when we are doing ptr is equals to and ampersand a this is and ampersand that will give the address that will provide the address of a to ptr so…
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever