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 6063491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:10:18+00:00 2026-05-23T09:10:18+00:00

I am confused about how Unary Operators work in C for Ones Complement, Logical

  • 0

I am confused about how Unary Operators work in C for Ones Complement, Logical Negation and preincrementing.

Ones complement works against 0 like this:

int main()
{
    int a;
    a = ~0;          // Ones complement
    printf("%d",a);  // prints as -1.
}

And logical negation works against 0 like this:

int main()
{
    int a;
    a = !0;          // Logical negation
    printf("%d",a);  // prints as 1.
}

But Preincrement against 0 generates a compiler error:

int main()
{
    int a;
    a = ++0;        //pre incrementing 0.  error: non-lvalue in increment
    printf("%d",a); 
}

Why don’t all three work considering they are all Unary Operators?

  • 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-05-23T09:10:18+00:00Added an answer on May 23, 2026 at 9:10 am

    The increment (++) and decrement (--) operators modify the thing that follows them. You can’t modify a literal or a constant. In contrast, the ! and ~ operators merely operate on a value, they don’t then assign the result anywhere.

    Loosely speaking, ++n means n = n + 1; n. That is, “take the value of n, add one to it, write that value back to n, and return the new value as the value of the expression.” So ++0 would mean 0 = 0 + 1; 0: “take the value of 0, add one to it, write that back to 0, and return the new value as the result of the expression.” Literals and constants cannot be left-hand values (you can’t assign to them).

    In contrast, ~n means “take the value of n and apply a bitwise NOT operation to it, return the result as the result of the expression”. n is unchanged, ~ doesn’t write back the updated value to its operand.

    So for example:

    int n = 0;
    int a;
    a = ~n;
    printf("a = %d, n = %d\n", a, n); // "a = -1, n = 0" -- `n` is unchanged
    

    vs.

    int n = 0;
    int a;
    a = ++n;
    printf("a = %d, n = %d\n", a, n); // "a = 1, n = 1" -- `n` is changed
    

    Increment (++) and decrement (--) are just different in that way than for ! or ~ (or, I think, any other unary operator — at least, I can’t immediately think of any others that modify their operand).

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

Sidebar

Related Questions

Very confused about this one. This code in views.py works, but only when I'm
I'm a bit confused about this. Does XMLHttpRequest work on a remote URL or
I've always been confused about this one. Consider the following loops: int [] list
I've always been confused about how the linker works, and it's a difficult subject
i'm confused about how to do inline functions in C++.... lets say this function.
Being confused again after reading about this anti-pattern and the many concerns about it
I am confused about strings and int. and can't validate a name to be
Totally confused about the data types required here. I have this Linq statement: var
I'm a bit confused about how facebook.logout(context) works. Because even after calling log out,
I'm confused about facebook and whether or not facebook is an openid provider like

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.