C Programming - Complicated Declarations - Discussion

Discussion Forum : Complicated Declarations - Find Output of Program (Q.No. 5)
5.
What will be the output of the program?
#include<stdio.h>
typedef void v;
typedef int i;

int main()
{
    v fun(i, i);
    fun(2, 3);
    return 0;
}
v fun(i a, i b)
{
    i s=2;
    float i;
    printf("%d,", sizeof(i));
    printf(" %d", a*b*s);
}
2, 8
4, 8
2, 4
4, 12
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
19 comments Page 2 of 2.

Sagar said:   1 decade ago
In this from global and local variable, local gets higher priority so that float i considered.

Sarika said:   1 decade ago
i is defined as float within the function and printf statement is also witin the same function so the latest value will be hold. 4 is correct

Priya said:   1 decade ago
But the i is the typdef of int which is of 2 byte than why 4 ?

Sandy said:   1 decade ago
@Sundar it may be the case that instead of taking i as float variable, it may treat it as a integer. Because typedef int i.

Means i is new name for integer.

Jes said:   1 decade ago
Here from fun(2,3)the value of a and b is 2,3&s value is 2
a*b*s=2*3*2=12

Prakash said:   1 decade ago
Yes sundar answer 4is correct but how it is 12 can any body explain please.

Bhavya said:   1 decade ago
Yes. Sundar is correct.

Sundar said:   1 decade ago
@Sharath

Because float i; ---> 'i' is a float variable.

Hence size of float is 4 bytes.

Sharath said:   1 decade ago
How sizeof(i) is 4 ? Please explain.


Post your comments here:

Your comments will be displayed after verification.