C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Find Output of Program (Q.No. 10)
10.
What will be the output of the program ?
#include<stdio.h>
int main()
{
struct byte
{
int one:1;
};
struct byte var = {1};
printf("%d\n", var.one);
return 0;
}
Discussion:
29 comments Page 2 of 3.
Mahi said:
1 decade ago
Can anyone explain about the statement?
int one:1;
int one:1;
Sivakumar said:
1 decade ago
int one:1 - means only one bit allocated to store 1.
Here pattern is 1.
Here MSB = LSB.
MSB = 1 means -ve value.
1 can be converted to 2's complement.
Than it's comes 1.
Than answer is -1.
Here pattern is 1.
Here MSB = LSB.
MSB = 1 means -ve value.
1 can be converted to 2's complement.
Than it's comes 1.
Than answer is -1.
Neeraja said:
1 decade ago
@Shivashanker.
If we assign 2 to one then 2 gets printed because here the left most bit is "0" (0010).
If we assign 2 to one then 2 gets printed because here the left most bit is "0" (0010).
Sandeep said:
1 decade ago
Thanks prashant.
D.shivashanker said:
1 decade ago
Here var is variable for struct byte type right, if here 2 is assigned to one (integer variable) what will happen?
Ashok said:
1 decade ago
Here var is variable for struct byte type, here 1 is assigned to one (integer variable) ;.
Pranav said:
1 decade ago
What is this line means here ?
struct byte var = {1};
struct byte var = {1};
Vikas said:
1 decade ago
Thanks Sundar.
Abhinav said:
1 decade ago
Thanks sundar.
Prashant o_O said:
1 decade ago
int a;
a=1; means 0000000000000001
and
int a:1;
a=1; means 1000000000000001
a=1; means 0000000000000001
and
int a:1;
a=1; means 1000000000000001
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers