Problem : 4


int ret (int ret)
    ret += 2.5;
    return (ret);

int main()
    int k = ret(sizeof(float));
    printf("here value is %d\n",++k);
    return 0;

// What's the output ? [Do not execute / run]
// Source :

3 thoughts on “Problem : 4

  1. #include <stdio.h>
    int main ()
        printf ("size of Boolean : %d\n", sizeof (bool) );
        printf ("size of Character : %d\n", sizeof (char) );
        printf ("size of Short Integer : %d\n", sizeof (short int) );
        printf ("size of Integer : %d\n", sizeof (int) );
        printf ("size of Long Integer : %d\n", sizeof (long int) );
        printf ("size of Float : %d\n", sizeof (float) );
        printf ("size of Double : %d\n", sizeof (double) );
        return 0;

    size of a data type is compiler dependent. Run the above code in your own preferable compiler.
    but as far as the problem concern, there is no confusion about the size of a float variable in C language.
    size of a Float = 4 bytes.
    i.e a float variable occupies 4 bytes of memory.

    value 4 passed to function ‘ret’
    ret += 2.5;
    as ‘ret’ is an integer variable, so to add 2.5 to ret has no effect after precision.
    ret += 2.5 is same as, ret += 2;
    ret = 6 is returned by function ret.

    returned value is kept by ‘k’
    before print, value of ‘k’ is pre-incremented by 1

    Correct Output : here value is 7

Leave a Reply

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

You are commenting using your 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