main( )

{

static int a[ ] = {0,1,2,3,4};

int *p[ ] = {a,a+1,a+2,a+3,a+4};

int **ptr = p;

ptr++;

printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);

*ptr++;

printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);

*++ptr;

printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);

++*ptr;

printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);

}

Answers were Sorted based on User's Feedback



main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3..

Answer / susie

Answer :

111

222

333

344

Explanation:

Let us consider the array and the two pointers with some address

a

0
1
2
3
4
100 102 104 106 108

p

100
102
104
106
108
1000 1002 1004 1006 1008

ptr

1000
2000

After execution of the instruction ptr++ value in ptr
becomes 1002, if scaling factor for integer is 2 bytes. Now
ptr – p is value in ptr – starting location of array p,
(1002 – 1000) / (scaling factor) = 1, *ptr – a = value at
address pointed by ptr – starting value of array a, 1002 has
a value 102 so the value is (102 – 100)/(scaling factor) =
1, **ptr is the value stored in the location pointed by
the pointer of ptr = value pointed by value pointed by 1002
= value pointed by 102 = 1. Hence the output of the firs
printf is 1, 1, 1.

After execution of *ptr++ increments value of the value in
ptr by scaling factor, so it becomes1004. Hence, the outputs
for the second printf are ptr – p = 2, *ptr – a = 2, **ptr = 2.

After execution of *++ptr increments value of the value in
ptr by scaling factor, so it becomes1004. Hence, the outputs
for the third printf are ptr – p = 3, *ptr – a = 3, **ptr = 3.

After execution of ++*ptr value in ptr remains the same, the
value pointed by the value is incremented by the scaling
factor. So the value in array p at location 1006 changes
from 106 10 108,. Hence, the outputs for the fourth printf
are ptr – p = 1006 – 1000 = 3, *ptr – a = 108 – 100 = 4,
**ptr = 4.

Is This Answer Correct ?    26 Yes 3 No

main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3..

Answer / rashmi

the logic given by u is wierd.......!!!!!!!!!!!!!!!!!!!

Is This Answer Correct ?    10 Yes 8 No

Post New Answer

More C Code Interview Questions

x=2 y=3 z=2 x++ + y++; printf("%d%d" x,y);

2 Answers  


How to access command-line arguments?

4 Answers  


Write a complete program that consists of a function that can receive two numbers from a user (M and N) as a parameter. Then print all the numbers between the two numbers including the number itself. If the value of M is smaller than N, print the numbers in ascending flow. If the value of M is bigger than N, print the numbers in descending flow. may i know how the coding look like?

2 Answers  


main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); } } a. 512, 256, 0, 0, 0 b. 256, 256, 0, 0, 0 c. 512, 512, 512, 512, 512 d. 256, 256, 256, 256, 256

2 Answers   HCL,


main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); }

1 Answers  






Develop a routine to reflect an object about an arbitrarily selected plane

0 Answers  


hello sir,is there any function in C that can calculate number of digits in an int type variable,suppose:int a=123; 3 digits in a.what ll b answer?

6 Answers  


what is the code of the output of print the 10 fibonacci number series

2 Answers  


main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }

1 Answers  


main() { int i=5; printf(“%d”,i=++i ==6); }

1 Answers  


Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

0 Answers  


main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; } a. Runtime error. b. Runtime error. Access violation. c. Compile error. Illegal syntax d. None of the above

1 Answers   HCL,


Categories