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 the right shift operator works on a numerical value?? eg:- 8>>3=?
first convert numerical value to binary value then arrange into bits and shift 3 bit on right then convert binary value to decimal value.
Abhishek
Can we have if inside else-if or else in C programming language?
Yes it is possible to do so. The if... else if..... else statements support one other inside themselves... so...
Kirthi
How do I get C help in Ubuntu?
Use command line tool 'man'. for example 'man printf' will give you details regarding printf function C
Ashmita
0 0
5
How are portions of a program disabled in demo versions?
By inserting comments in the program Single line comment denoted by // Multi line comment denoted by /* */
Akhilesh
0 0
5
What is the difference between text and binary modes?
By default files are text mode. Binary modes are machine readable form.
Raj

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

Ask a Question

Related Lessons

Swapping variable contents using C
/* WAP to swap the content of variables using C*/ //Header files #include<stdio.h>#include<conio.h> //Main function void main(){ //Variable declaration of type integer int a,b,c; //function...
S

What is a Programming Language
What is a Language? Language is a communication system of human. What is a programming Language? A programming Language is a formal constructed language design to communicate...

How do i get best Campus / Off Campus Placement?
Companies are looking for Skilled Freshers. So build your technical skills while doing MCA / BTech / BCA / BSc (IT or CS) into below areas- 1. Strong your programming & debugging skills ...

C Program-Error Handling[Program Exit Status]
//Header files #include<stdio.h>#include<conio.h>#include<stdlib.h> //Main Function void main(){ int dividend=20; int divisor=5; int quotient; //Function for clearing screen clrscr();...
S

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