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);
}
Discussion:
19 comments Page 1 of 2.
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.
Means i is new name for integer.
Saket said:
1 decade ago
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?
Ashok said:
7 years ago
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.
Prakash gautam said:
8 years ago
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.
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
Prakash gautam said:
8 years ago
The typedef int i is global and float i is local and local variable has more priority in function.
Ajay said:
8 years ago
The float i is local variable so it has max priority than typedef int i which is global variable.
Sagar said:
1 decade ago
In this from global and local variable, local gets higher priority so that float i considered.
Sundar said:
1 decade ago
@Sharath
Because float i; ---> 'i' is a float variable.
Hence size of float is 4 bytes.
Because float i; ---> 'i' is a float variable.
Hence size of float is 4 bytes.
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
a*b*s=2*3*2=12
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers