Problem : 3


#include<stdio.h>

int main ()
{
    int a[10];
    printf("%d\n", *a+1-*a+3);
    return 0;
}

// What's the output ? [Do not execute / run]
// Source : http://www.youngprogrammer.com/

6 thoughts on “Problem : 3

  1. Simple:
    *a+1-*a+3
    = (*a) + 1 – (*a) + 3
    = a[0] + 1 – a[0] + 3
    = a[0] – a[0] + 1 + 3

    we don’t know the value of a[0]. suppose a[0] = some junk value 21586

    = 21586 – 21586 + 1 + 3
    = 1 + 3
    = 4

    if we declare an array as A[10]. then A contains the address of the 1st element of that array. that means A is a pointer. but it is a read-only pointer. however, as A is a pointer so *A is the value of the 1st element of that array.
    * operator on pointer has a higher precedence than + or -. so *A+1 means (*A)+1. so whatever the value of A[0], it has been added and then subtracted. tar mane tal diya abar tal niya neoa hoiche. so oi tal niya matha ghamanor kichu nai :p baki 1 + 3 er folafol ase 4. eibar bujha geche?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s