Solved explain it with output

September 28, 2012 at 06:03:03
Specs: Windows 7
#include<stdio.h>

struct marks
{

int p:3;
int c:3;
int m:2;
};
void main()
{
struct marks s={2,-6,5};

printf("%d%d%d",s.p,s.c,s.m);
getch();
clrscr();
}


See More: explain it with output

Report •

✔ Best Answer
September 28, 2012 at 08:22:55
Since you'll need the name of a feature before you can search on it, you're looking at bit fields.

As for why you're getting the output you're getting, it involves binary math. The digit after the colon is the size of the variable. "p" is 3 bits, "c" is 3 bits, and "m" is 2 bits. I assume your notes include how to convert decimal to binary, so reference that and write out 2, -6, and 5 in binary.

How To Ask Questions The Smart Way



#1
September 28, 2012 at 06:25:22
It's the strangest thing. I ran your program, and it just repeats, over and over:
Do your own homework
Do your own homework
Do your own homework

How To Ask Questions The Smart Way


Report •

#2
September 28, 2012 at 06:30:53
no its not repeating

Report •

#3
September 28, 2012 at 07:04:41
Yeah, I don't understand it either. There's only one string in that program, and it looks nothing like the output. My only explanation is GCC itself is so dismayed at the amount of effort you're showing, it revolted.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
September 28, 2012 at 07:43:16
output is 221 but how?

Report •

#5
September 28, 2012 at 07:52:19
That's a good question! Find the solution and you will have learnt some useful things about C. The journey to that solution is your education.

Read your C textbooks to learn exactly what the struct declaration means.


Report •

#6
September 28, 2012 at 08:22:55
✔ Best Answer
Since you'll need the name of a feature before you can search on it, you're looking at bit fields.

As for why you're getting the output you're getting, it involves binary math. The digit after the colon is the size of the variable. "p" is 3 bits, "c" is 3 bits, and "m" is 2 bits. I assume your notes include how to convert decimal to binary, so reference that and write out 2, -6, and 5 in binary.

How To Ask Questions The Smart Way


Report •

Ask Question