recategorized by
251 views
0 votes
0 votes
main()
{
int m,row, col;
int *ptr ,sum = 0 ;
  int arr[2][2][2] ={1,2,3,4,5,6,7,8};
 int(*p)[2][2] ;
   p = arr;
  for(m=0;m<2;m++)
1  {
  ptr =  p+m;
  for(row= 0 ;row<2;row=row+2)
   {
   ptr = ptr + row ;

   for(col=0;col<2;col=col+1)
   {
   sum = sum + *(ptr+col);
   }
   }
   }
   printf("%d",sum);

   }

can someone show me with a diagram how it is processing morever , at ptr = p + m  , when control go here  ptr stores 1 , my question is ptr should hold address because its a pointer , thanks
recategorized by

1 Answer

0 votes
0 votes
In the line ptr=p+m; there is a need for typecasting as p is a ponter to two dimensional array of size 2*2..and ptr is a pointer to integer..so it should be written as

Ptr=(int*)(p+m);

And for ur question ..indeed ptr will hold the address and initially it is holding the address of first element of three dimensonal array  ...                                    

May b this will help u to solve this ques ..

Related questions

1 votes
1 votes
0 answers
1
Ashish Roy 1 asked Mar 16, 2019
1,684 views
In the above 4 Statements which would print 123 as output ? Explain also.
2 votes
2 votes
1 answer
2
1 votes
1 votes
1 answer
3
Na462 asked Jan 8, 2019
1,437 views
#include <stdio.h>main (){unsigned x = -10;int X = 20;if (X x) printf ("Hello");else{ printf ("%d",x); printf ("Jello"); }}
7 votes
7 votes
3 answers
4
Parshu gate asked Nov 20, 2017
780 views
What is the output of the following program?#include<stdio.h int main() { int array[]={10, 20, 30, 40}; printf(“%d”, -2[array]); return 0; }$-60$$-30$$60$Garbage valu...