Question

Given the following code: int x = 0; int y = 10; int *ptr = &x;...

Given the following code:

int x = 0;
int y = 10;
int *ptr = &x;
*ptr = -55;
x += -52;
ptr = &y;
*ptr += 52;
printf("%d\n", x);

What is printed to the screen?

Homework Answers

Answer #1

Explanation :

It will print -107, as *ptr contains the address of x.

first time x = 0

then ptr which contains the address of x is found value -55

after that x also become -55

now x += -52, taking the value of x to -107

C Program:

#include <stdio.h>

int main()
{
    int x = 0;
    int y = 10;
    int *ptr = &x;
    *ptr = -55;
    x += -52;
    ptr = &y;
    *ptr += 52;
    printf("%d\n", x);

    return 0;
}

Output:

Thumbs Up Please !!!

Know the answer?
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
Similar Questions
Given the following function in C++: int main(void) { int a = 2; int b =...
Given the following function in C++: int main(void) { int a = 2; int b = myFunction(a); a = b + 1; b = myFunction(a); cout << ”b = ” << b << endl; return 0; } int z = myFunction(int x) { static int n = 0; n = n + 1; int z = x + n; return z; } What is printed by the cout on the screen?
C PROGRAMMING LANGUAGE The following code written in C programming language was run and displays 997705320....
C PROGRAMMING LANGUAGE The following code written in C programming language was run and displays 997705320. Explain why and how this program outputs this number. int main(void) { int a = 5, b =20; int* ptr = &a; int** ptr2 = &ptr; printf("%d\n", ((int)*ptr * (int)*ptr2)); return 0; }
what is the output from the following code? int number=10; int* ptr = &number; number+=10; cout<<*ptr;
what is the output from the following code? int number=10; int* ptr = &number; number+=10; cout<<*ptr;
Please find the errors of the following code a) int x[5]; int k = 10; for...
Please find the errors of the following code a) int x[5]; int k = 10; for (k = 0; k <= 5; k++) { x[k] = k -1; } b) int x[5]; for (k = 1; k <= 5; k++) { cout << x[k-1] << endl; } c) int x[5]={1,2,3,4,5}, y[5]; y = x; for (k = 0; k < 5; k++) { cout << y[k] << endl; } d) int size; cin >> size; int myArr[size];
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main()...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main() { int x,y; float result; char ch; //to store operator choice printf("Enter first number: "); scanf("%d",&x); printf("Enter second number: "); scanf("%d",&y); printf("Choose operation to perform (+,-,*,/): "); scanf(" %c",&ch); result=0; switch(ch) { case '+': result=x+y; break; case '-': result=x-y; break; case '*': result=x*y; break; case '/': result=(float)x/(float)y; break; case '%': result=x%y; break; default: printf("Invalid operation.\n"); } printf("Result: %d %c %d = %.2f\n",x,ch,y,result); // Directly...
1. Identify and correct the errors in each of the following statements: a) for (a =...
1. Identify and correct the errors in each of the following statements: a) for (a = 25, a <= 1, a--); {printf("%d\n", a);} b) The following code should print whether a given integer is odd or even: switch (value) {case (value % 2 == 0):puts("Even integer");case (value % 2 != 0):puts("Odd integer");} c) The following code should calculate incremented salary after 10 years: for (int year = 1; year <= 10; ++year) {double salary += salary * 0.05;}printf("%4u%21.2f\n", year, salary);...
Translate C code into MIPS. Do not include an exit syscall int proc1( int a, int...
Translate C code into MIPS. Do not include an exit syscall int proc1( int a, int b ) { if ( proc2( a, b ) >= 0 ) return 1; else return -1; } int proc2( int a, int b ) { return (a*10) & (b*10); } int main() { int a = 9; int b = -10; int c = a + b + proc1( a, b ); printf("%d\n", c ); return 0; }
1.    Given the following segment of code: (If there is nothing output, write None.) int x;...
1.    Given the following segment of code: (If there is nothing output, write None.) int x; int y; cin >> x; cin >> y; while (x > y) {     x -= 3;     cout << x << " "; } cout << endl;        a.    What are the output and final values of x and y when the input is 10 for x and 0 for y? [2, 2, 2]               Output                                                                                                                                                                                                    x = ______________                                                                                                                                                                                                   ...
Below is C code and Python code for an algorithm. C code: void foo( int n,...
Below is C code and Python code for an algorithm. C code: void foo( int n, int A, int B, int C ) { if( n==1 ) { printf("%d to %d\n",A,B); return; } foo( n-1, A, C, B ); printf("%d to %d\n",A,B); foo( n-1, B, C, A ); Python code: def foo(n , A, B, C): if n==1: print A, "to", B return foo(n-1, A, C, B) print A, "to", B foo(n-1, B, C, A) Let Hn be the number...
please wirte the mips code main() { x = 2*foo(4*y+7); x = x+(4*y+7); } int foo...
please wirte the mips code main() { x = 2*foo(4*y+7); x = x+(4*y+7); } int foo (int n) { int junk[10] = {0,1,2,3,4,5,6,7,8,9}; junk[4] += 2; if (n<1) return 1; else return (foo(n-1) + junk[4] + n); }