Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the output to the print statement?

Tags:

arrays

c

pointers

Shouldn't the output be 6 as it should print B[0][2] ? The output is coming out to be 4. which is B[1][0]

main()
{    
    int B[2][3]={2,3,6,4,5,8};
    printf("%d",**B+2);
}
like image 354
Bhavya Bhatia Avatar asked Dec 14 '22 12:12

Bhavya Bhatia


1 Answers

**B+2 is equivalent to (**B) + 2

**B is equal to B[0][0] which is 2 in your array.

Hence the seen output.

If you want 6, what you need is *(*B + 2)

More info on this here and here

like image 165
Ghazanfar Avatar answered Dec 27 '22 14:12

Ghazanfar