C program(memory diagram with pointers)

User Generated

wrssawb

Programming

Description

What are the outputs of the following program. Explain with the help of the memory model as it was shown 

in the lecture. 

http://teg.uwasa.fi/courses/tlte2110/lectures/Lecture_4.pdf check page 11, 7,5 of the lecture note
#include <stdio.h> 
int main(void) 
{ 
 int array[] = {9,4,5,3,8,2,1,6}; 
 int *ptr; 
 int *qtr; 
 int **pptr; 
 int i = 0; 
 
 
 ptr = array; 
 qtr = &array[6]; 
 
 printf("%d\n",*ptr - *qtr); // Output:__________________________________ 
 
 ptr = ptr + 2; 
 
 ptr[1] = *qtr; 
 
 for(i = 0; i < 8; i++) 
 printf("%d ", array[i]); // Output:________________________________________ 
 
 printf("\n"); 
 
 pptr = &qtr; 
 
 printf("%d\n",**pptr); // Output:__________________________________ 
 
 return 0; 
} 

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer


Anonymous
Really helped me to better understand my coursework. Super recommended.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags