UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do I store a negative integer in C?

Asked by Last Modified  

Follow 4
Answer

Please enter your answer

In the C programming language, unsigned int is used to store positive values only. However, when I run the following code: unsigned int x = -12; printf("%d", x);
Comments

Advance Excel And VBA Training

13 down vote Passing %d to printf tells printf to treat the argument as a signed integer, regardless of what you actually pass. Use %u to print as unsigned. 6 down vote It all has to do with interpretation of the value. If you assume 16 bit signed and unsigned integers, then here...
read more
13 down vote Passing %d to printf tells printf to treat the argument as a signed integer, regardless of what you actually pass. Use %u to print as unsigned. 6 down vote It all has to do with interpretation of the value. If you assume 16 bit signed and unsigned integers, then here some examples that aren't exactly correct, but demonstrate the concept. 0000 0000 0000 1100 unsigned int, and signed int value 12 1000 0000 0000 1100 signed int value -12, and a large unsigned integer. For signed integers, the bit on the left is the sign bit. 0 = positive 1 = negative For unsigned integers, there is no sign bit. the left hand bit, lets you store a larger number instead. So the reason you are not seeing what you are expecting is that. unsigned int x = -12, takes -12 as an integer, and stores it into x. x is unsigned, so what was a sign bit, is now a piece of the value. printf lets you tell the compiler how you want a value to be displayed. %d means display it as if it were a signed int. %u means display it as if it were an unsigned int. c lets you do this kind of stuff. You the programmer are in control. Kind of like a firearm. It's a tool. You can use it correctly to deal with certain situations, or incorrectly to remove one of your toes. one possibly useful case is the following unsigned int allBitsOn = -1; That particular value sets all of the bits to 1 1111 1111 1111 1111 that can be useful sometimes. read less
Comments

Trainer

in C we can store negative and positive both values
Comments

View 1 more Answers

Related Questions

How do I write a C program to print the total number of a single-digit prime number using a loop?
total number of single digit prime number that means your prime number starts from 2 and less than 9 so you can take loop for this range
Momin
0 0
7
What is = and == in C language?
= is assignment operator while ==is comparision operator
Sayed
0 0
7
How to enable or disable USB using C program?
Already given answer kindy see in my back command.
Arindom M.
Who created C?
The C was primarily created by Dennis Ritchie, an American computer scientist, in the early 1970s while working at Bell Labs. C was designed as a system programming language, initially for building utilities...
Srinivasan
0 0
8
Can we pass arguments in the main function in C language?
Yes. it is possible to pass arguments into the main function.
Mukesh
0 0
7

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Functions In C Programming
A C-language program is nothing but collection of Function, these are the building blocks of a ‘C’ program. Generally, a function mans a task. “Function is a...

Structures in C
A structure is a collection of one or more data members possibly of different data types, grouped together under a single name for convenient handling. Defining a Structure: In general terms,...

Basic Concepts of Web Designing
An introduction to domain names, web servers, and website hosting 1)What is the web? In a nutshell, the web is a whole bunch of interconnected computers talking to one another. The computers (on the...

INTRODUCTION TO PROGRAMMING LANGUAGES
Language is a medium for communication. If we want to perform anything with another person, we can know the human language as a human being. Similarly, if we want to perform anything with a computer, we...

Design your own Mouse Driver in C Language
Mouse Driver (msdrv.h) #include #include union REGS i,o; restrictmouseptr(int x1, int y1, int x2, int y2) { i.x.ax=7; i.x.cx=x1; i.x.dx=x2; ...

Recommended Articles

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more