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
How do I get 6 power 13 in c language?
#include <stdio.h> #include <math.h> int main() { double result = pow(6, 13); printf("6 to the power of 13 is: %f ", result); return 0; }
Raju
0 0
6
What does %d mean in the C programming language?
To specify the integer values in printf and scanf.
Vikas
0 0
6
How do you print an address?
int main(){ int a=5; printf("Address of variable a is: %d",&a); return 0; }
Prakash
2 0
6
What is a void main() in the C programming language?
Void main () is the entry point for execution in C program. The void is a keyword that represents function will not return anything but a void value. Main is the name of the function and () represents...
Ambar
0 0
5

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

Ask a Question

Related Lessons

Internet of Things, Social Media Becoming Part of E-Discovery Landscape
The days when e-discovery consisted of handing over copies of e-mails to address Freedom of Information Act (FOIA) requests, compliance regulations or other legal obligations are over. Now, it's just as...

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...

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

Working with C/C++ applications
Inorder to learn C and C++ programming languages one can work with various editors available.To name a few are the most popular one is turbo c++, DEV C++, Eclipse, NetBeans. Here are the screen shots...

C Program-String Palindrome
//Header files #include<stdio.h>#include<conio.h>#include<string.h> //Main function void main(){ char mystring; int i,length; int flag=0; //Function for clearing screen clrscr();...

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