Question

In: Computer Science

Write a program (in Q0.c) to do the following: In main(), declare an integer x. Print...

Write a program (in Q0.c) to do the following:

In main(), declare an integer x. Print the address of x (using the address-of operator). Pass x as an argument to a function void fooA(int* iptr). (Hint: can you pass x itself directly?)

In fooA(int* iptr), print the value of the integer pointed to by iptr, the address pointed to by iptr, and the address of iptr itself.

In the main function, following the call to fooA(...) , print the value of x.

Implement function int fooB(int* a, int *b, int c) which should perform the following computations:

Assign a + b to c.

Set the value pointed to by a to the value pointed to by b.

Set the value pointed to by b to double its original value.

Return the value of c.

Solutions

Expert Solution

#include <stdio.h>

void fooA(int* iptr);
int fooB(int* a, int *b, int c);

int main(void)
{
   int x,y;
   int *a,*b,c;
   *a = 5;                   //initialize values pointed to by pointers a and b
   *b = 3;
   printf("Address of x :%u",&x);
   fooA(&x);                     //call to function fooA()
   printf("\nx = %d",x);
   y=fooB(a,b,c);               //call to function fooB()
   printf("\nfooB returns : %d",y);
   return 0;
}
void fooA(int* iptr)
{
   printf("\nvalue of the integer pointed to by iptr %d",*iptr);
   printf("\naddress pointed to by iptr %u",iptr);
   printf("\naddress of iptr: %u",&iptr);
}
int fooB(int* a, int *b, int c)
{
   c = *a +*b;
   *b = *a;
   *b = 2 * (*b);
  
   return c;
}


output:

Address of x :4287071804
value of the integer pointed to by iptr 1433419341
address pointed to by iptr 4287071804
address of iptr: 4287071776
x = 1433419341
fooB returns : 8

Related Solutions

(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
Write a program in c++ to do the following : (1) Declare an array a of...
Write a program in c++ to do the following : (1) Declare an array a of size 10 and three pointer variables p, q, and v. (2) Write a loop to fill array a with values 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 (3) write following statement: p= &a[2]; q = &a[5]; i = *q - *p; cout<<“The value of i is”<< i; i = *p - *q; cout<<“The value of i is %d”<< i; 4) assign...
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an integer pointer p. 3. Let p pointing to the array a[ ]. 4. Use p (you have to use p) to put 0 into the first element of this array, 2 into the second element, 4 into the 3rd element, 6 into the 4th element, ... 198 into the 100th element of this array. 5. Use a (you have to use a) to display...
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt...
c++ please Write and testa C++ main program that: declare an array arrof 6 integers Prompt the user for 6 integer values and store them in arr. Prompt the user for a target integer target. Search for targetin arr. If targetis found to match an element in the arr, then the program prints out a message which contains the address of the found element, otherwise, if no element found then the message “the element target not found” will be printed...
assume that the following pseudocode is executed in a program module main declare x = 1...
assume that the following pseudocode is executed in a program module main declare x = 1 declare sum = 0 declare max = 5 while ( x < max) Display "x is ", x set x = x + 1 set sum = s + x end while end module after the execution of this program the final value of x is_____ and the final value of sum is_____
Write a program to read in a collection of integer values, and find and print the...
Write a program to read in a collection of integer values, and find and print the index of the first occurrence and last occurence of the number 12. The program should print an index value of 0 if the number 12 is not found. The index is the sequence number of the data item 12. For example if the eighth data item is the only 12, then the index value 8 should be printed for the first and last occurrence....
C++ Vectors. Create a program do the following in the program: 1. declare an vector without...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without specifying the size 2. use push_back to add random integers between 100 and 999 to the vector 3. write a function that returns the smallest, largest, and average of the numbers in the vector display the smallest, largest, and average of the numbers in the vector
Problem: Write a C/C++ program to implement a function that returns 1 when an integer x...
Problem: Write a C/C++ program to implement a function that returns 1 when an integer x contains an odd number of 1s (in its binary representation) and 0 otherwise. You can consider x as a four byte integer, i.e. w = 32 bits. Constraint: Your solution can use at most 12 arithmetic, bitwise, and logical operations.
Write a C++ program for the following problem: Calculate and print the area and volume of...
Write a C++ program for the following problem: Calculate and print the area and volume of a cone inside a While  loop that goes from 1 to 20 with a step of .5. (the step is 1/2 or Point 5, so you go 10, 10.5,11, 11.5) Note: Your loop variable will need to be a double data type Use two decimal places on all numbers that are double data type. This will be a table with 3 columns. Don't worry about...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT