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.
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)
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?
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.
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?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers