Write a program in Q0c to do the following In main declare a

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.

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(\"\ x = %d\",x);
   y=fooB(a,b,c);               //call to function fooB()
   printf(\"\ fooB returns : %d\",y);
   return 0;
}
void fooA(int* iptr)
{
   printf(\"\ value of the integer pointed to by iptr %d\",*iptr);
   printf(\"\ address pointed to by iptr %u\",iptr);
   printf(\"\ address of iptr: %u\",&iptr);
}
int fooB(int* a, int *b, int c)
{
   c = *a +*b;
   *b = *a;
   *b = 2 * (*b);
  
   return c;
}


output:

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site