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

Why is C still so popular?
C remains popular for several reasons, and its enduring popularity can be attributed to a combination of historical significance, efficiency, and versatility. Here are some key reasons why C is still widely...
A
0 0
6
hello sir my name is suryateja i am studying in diploma in computer science and engineering my college complect in c language subject i practice with in simple programs my write to won programs how it you?
Hi Syateja, if I understand your questions correctly let me answer. Best thing to learn and progress is to practice writing programs, initially small programs then gradually can write complex program....
Suryateja
Why are there so many programming languages if most programmers use C, C++, Java, and PHP?
This question has the same answer as the question"Why there are so many languages?" has... As they were ask meant for different purpose to serve for different platforms... For short: Link it to the languages used
Veerendra
0 0
7
Do every operator has an Associativity?
Yes, every operator will have an associativity.
Basundhara
0 0
5
What is meant by "bit masking"?
Mask means to block in bit masking, blocking can be done by bit by bit e.g. 0101 1000 OR -------------- 1101
Kiran
0 0
6

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

Ask a Question

Related Lessons

Lets know about far, near and huge pointers for fresher interview purpose
All of these three candidates relate to 16 bit architecture where segmented memory architecture was there. They are not at all relevant for present days 32 or 64 bit architecture where the way of memory...

C and C++ programming with memory level debugging
Understanding C and C++ programming by using memory level debugging. Step 1: Understand the Memory map of C executable Step 2: Start memory level debugging using popular IDE Step 3: Find the memory...

10 Tips to improve your learning
1. Have a quick revision of topics that you have read in past three days before you start studying a new topic. 2. Make your own notes containing the summary of the topic. 3. Allot proper timing for...

Software Development Training In Jaipur
Satyam Web Solution provides website designing &development and software designing &development training in Jaipur for various stream’s students. MCA 6 month Industrial Training/Internship B....

Datatypes in C Language
Data types in C Language Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that...

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