Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write C code to do the following: a. Declare an integer (named a) and a point

ID: 2246507 • Letter: 1

Question

1. Write C code to do the following:

a. Declare an integer (named a) and a pointer to an integer (named b)

b. Assign the pointer to “point to” the integer

c. Increment the integer by using the pointer.

2. Write C code to do the following:

a. Declare both an integer and a pointer to an integer

b. Set the pointer equal to memory location 0x80001800.

c. Read contents of the memory location (by using the pointer) into the integer you declared.

d. Then set the pointer equal to memory location 0x8000180C.

e. If the least significant bit of the memory location you read is 1, set the contents of memory location 0x8000180C to 0. If the least significant bit is 0, set the contents of the memory location to 0x1FF.

Explanation / Answer

1
#include<stdio.h>

int main() {
   int a;
   int *b;
  
   a = 5;
   b = &a;

   printf("before change a = %d " ,a)

   *b = b* + 1;

   printf("after change a = %d " ,a)
  
}

2
#include<stdio.h>

int main() {
   int a;
   int *b;

   b = 0x80001800;
   a = *b;

   b = 0x8000180C;

   if (a & 1) //reads least significant bit
       *b = 0; //if lsb is 1
   else
       *b = 0x1FF; //otherwise
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote