Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8343471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:04:28+00:00 2026-06-09T06:04:28+00:00

the program is : typedef struct xp { int a:2; int b:2; int c:1;

  • 0

the program is :

typedef struct xp {
        int a:2;
        int b:2;
        int c:1;
} xp;

int main(void)
{
        xp x;
        memset(&x, 0, sizeof(xp));

        x.a = 1;
        x.b = 3;
        x.c = 1;

        printf("%d\n",x.a);
        printf("%d\n",x.b);
        printf("%d\n",x.c);

        return 0;
}

I get 1 -1 -1, why? How are a, b and c stored in x? What happened when printf(“%d\n”,x.a); is executed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:04:30+00:00Added an answer on June 9, 2026 at 6:04 am

    You’re using a signed type for your bitfields, which means you’ve created what amounts to two two-bit signed integers, and one one-bit signed integer.

    The possible values for a two-bit signed integer (two’s complement) are: -2, -1, 0, and 1:

    The possible values for a one-bit signed integer (two’s complement) are -1 and 0.

    By storing values that “don’t fit”, like you have done in these lines:

    x.b = 3;
    x.c = 1;
    

    You will get strange behaviour as the bit patterns you store are interpreted differently when read. You can have a similar experience by doing something like:

    char x = 58147;
    

    on a machine with an 8-bit char type, that value won’t fit, so you’ll read something different back when accessing x.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this program: #include <map> #include <vector> typedef std::vector<int> IntVector; typedef std::map<IntVector,double> Map; void
#include<stdio.h> #include<string.h> #define USER_MEM (10*1024) typedef struct { unsigned short int vol_level; int mute_stat;
I have a problem with the typedef keywords in C language. In my program,
This program returns: package main import ( flag fmt ) func main() { num_agents
I'm having trouble implementing a Stack using a linked list with struct. The program
I made a program which is still in development. I did not declared main
I have a code: #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> typedef struct
gcc 4.4.4 c89 I have the following code in my channel.h file typedef struct
Program that calculates and shows the value of (2 to the 10th power) This
program to output all 4 digit numbers where no prior digit is greater than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.