C Programming - Complicated Declarations - Discussion
Discussion :: 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);
}
[A].
2, 8 [B].
4, 8 [C].
2, 4 [D].
4, 12
Answer: Option D
Explanation:
No answer description available for this question.
Sharath said:
(Sep 26, 2010)
How sizeof(i) is 4 ? Please explain.
Sundar said:
(Feb 3, 2011)
@Sharath
Because float i; ---> 'i' is a float variable.
Hence size of float is 4 bytes.
Bhavya said:
(Mar 18, 2011)
Yes. Sundar is correct.
Prakash said:
(Oct 29, 2011)
Yes sundar answer 4is correct but how it is 12 can any body explain please.
Jes said:
(Dec 10, 2011)
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
Sandy said:
(Jun 15, 2012)
@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.
Priya said:
(Aug 11, 2012)
But the i is the typdef of int which is of 2 byte than why 4 ?
Sarika said:
(Oct 22, 2012)
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
Sagar said:
(Dec 2, 2013)
In this from global and local variable, local gets higher priority so that float i considered.
Saket said:
(Oct 13, 2014)
Can anybody please explain when we declare float int; it will give an error but when we use typedef int I then float i; does not give an error why?
Sunil said:
(Aug 1, 2015)
i is declared as float.
Lavanya said:
(Oct 7, 2015)
Can you explain this I can't understand?
Neha said:
(Nov 28, 2016)
Please, anybody explain the value of i.
Udhaya said:
(Nov 30, 2016)
typedef void i means? Anyone explain me.
Prakash Gautam said:
(Jun 13, 2017)
Here i is in sizeof is from float i not from typedef you can check it by taking char i instead of float i than find the sizeof(i) it will give 1.
Prakash Gautam said:
(Jun 13, 2017)
The typedef int i is global and float i is local and local variable has more priority in function.
Ajay said:
(Jul 11, 2017)
The float i is local variable so it has max priority than typedef int i which is global variable.
Shyam said:
(Jul 27, 2017)
Hi, please explain the 3 bit which is given to b.
Ashok said:
(Sep 29, 2018)
Float variable takes 4bytes and the remaining statement will be computed as a*b*s=2*3*2=12 first statement it will print size and then computation.