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 1 of 3.
Codedamn said:
2 years ago
This happens because in C when using bit fields, the value -1 is typically used to represent true or on for 1-bit integers.
Jagadesh said:
8 years ago
Hello everyone.
Anybody can explain what is the meaning for this statement int one:1;?
Anybody can explain what is the meaning for this statement int one:1;?
(2)
Shrihari said:
8 years ago
Can anyone explain me. How -1?
Archana said:
10 years ago
What is the difference between int a:1 and int a=1?
Aditi said:
1 decade ago
Can anyone please explain in detail?
What does a:1 mean?
How is this whole thing working?
What does a:1 mean?
How is this whole thing working?
Rahul said:
1 decade ago
What is declaration just like int : what is this?
Sushant Choudhary said:
1 decade ago
I would say A or B could be right depending upon the endianness of the system.
Devendra said:
1 decade ago
The output will not be -1 on little endian systems, as simple as that.
Chitra said:
1 decade ago
For signed integers the leftmost bit will be taken for +/- sign, right?
So here 1 is treated as a sign, so it should print only a minus right? why is it printing -1? please anyone say?
So here 1 is treated as a sign, so it should print only a minus right? why is it printing -1? please anyone say?
Vasantha said:
1 decade ago
@Neeraja.
If we assign 2 to one(integer variable) then we get -2 as the answer because as int a:1, when we pass 2 as value we get 1000000000000010 which means -2.
If we assign 2 to one(integer variable) then we get -2 as the answer because as int a:1, when we pass 2 as value we get 1000000000000010 which means -2.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers