Explain the functionality of the following lines of code Mak

Explain the functionality of the following lines of code? Make particular reference to the final program output. double *p, *q; q = malloc(sizeof(double)); *q = 3.14; P = q; *q = 6.66; printf(w\\tOutput 1: %.2f\ \\tOutput 2: %.2f\ \",*q,* f) Give an example of two while loops populating a two dimensional array.

Solution

e) This program is creating two pointer and allocating memory for pointer q to store a double.

Then it assign a value of 3.14 to location pointed by ointer q.

Then it assign q to p essentially making both of them to point to same location.

Then it change value at location pointed by q which is also pointed by p.

Finally it print values stored at address pointed by pointer p and q which are same.

This program will print value of *p and *q as 6.66.

f)

#include <stdio.h>

int main() {
int arr[5][10];
int n = 5;
int m = 10;
  
int i = 0,j = 0;
  
while ( i < n)
{
j = 0;
while (j < m)
{
  
arr[i][j] = 20; // Storing random value. comment this if uncommenting below lines.
// Please uncomment this part if you want to pick values from command line.
// int value;
// scanf(\"%d\", &value);
// arr[i][j] = value
j++;
}
i++;
}
   return 0;
}

 Explain the functionality of the following lines of code? Make particular reference to the final program output. double *p, *q; q = malloc(sizeof(double)); *q

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site