22,332 views
62 votes
62 votes

Consider the following C program

#include<stdio.h>  
int main()  {
    static int a[] = {10, 20, 30, 40, 50};
    static int *p[] = {a, a+3, a+4, a+1, a+2};
    int **ptr = p;
    ptr++;
    printf("%d%d", ptr-p, **ptr);  
    
}  

The output of the program is _______.

11 Answers

0 votes
0 votes

i have assumed some addresses hope so you will get this

0 votes
0 votes

In Layman's terms:

ptr-p = location of the block where ptr points - location of the block where p points.
ptr and p point to neighbouring cells, hence their difference is 1.
You can also see that as subtracting indices, which works in all the cases.
ptr points to index 1, and p points to index 0.

 

Now, dereference ptr twice.

ptr » a+3 » 40

 

So, 140.

Answer:

Related questions

47 votes
47 votes
8 answers
3
go_editor asked Feb 14, 2015
15,866 views
Consider the following C program segment.# include <stdio.h int main() { char s1[7] = "1234", *p; p = s1 + 2; *p = '0'; printf("%s", s1); }What will be printed by the pro...