Thread: Signed and Unsigned in variables, including static type.

  1. #1
    Banned
    Join Date
    Apr 2015
    Posts
    596

    Signed and Unsigned in variables, including static type.

    Hello, I find it hard to make a distinction between when I should write unsigned int(or any other types) or signed int or even just write int without any tags (singed/unsigned/static) before? we generally are not using those types but I'm curious for knowing why we use them (static/signed/unsigned), what is the goal of using them, and what are they standing for?
    Moreover, if you can give an practical example while explaining then would be appreciated much.


    thanks.
    Last edited by RyanC; 05-24-2015 at 05:16 AM.

  2. #2
    Registered User
    Join Date
    May 2013
    Posts
    228
    Take a look here.

  3. #3
    Banned
    Join Date
    Apr 2015
    Posts
    596
    Quote Originally Posted by Absurd View Post
    Take a look here.
    so the difference between them(signed/unsigned) is just from byte's capacity, ye?

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,112
    Quote Originally Posted by RyanC View Post
    so the difference between them(signed/unsigned) is just from byte's capacity, ye?
    Capacity" is not a good description.

    Most any variable without the word, "unsigned" in front is a signed variable. (A char can be either signed or unsigned by default, depending on the compiler.)

    The "Capacity" of a 32 bit integer is 4 bytes, or 4,294,967,296 different values, signed or unsigned. The RANGE of the values is different.

    Signed int range == -2,147,483,648 to 2,147,483,647 (Negative to Positive)
    Unsigned int range == 0 to 4,294,967,296 (Zero or Positive)

    The same applies to all other integer data types. There are no "Unsigned" floating point data types. All are considered Signed, and the "Range" can be seen at the site @RyanC mentioned above.

    "Static" is not a "Data Type" but affects the visibility and persistence of the data.

    A Static "Global" variable is declared/defined outside of any function, and is visible from point of declaration/definition to the end of the file, and is not passed to the linker. It can be accessed by any function in the file after it is seen.

    A Static "Local" variable defined inside of a function, can only be seen inside the function and retains it's value between calls to the function. Non-static local variables DO NOT retain their values between calls to the function.

    You need to pick up a good book on the C Language, study, and program the Exercises at the end of each chapter. Alternatively, take a course from a qualified instructor.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 07-24-2012, 10:41 AM
  2. Why can't 'float' variables be assigned to signed or unsigned?
    By cplusplusnoob in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2012, 12:02 PM
  3. Type Convert (Static Array TO unsigned char ) Help.
    By userpingz in forum C++ Programming
    Replies: 1
    Last Post: 10-28-2009, 06:41 AM
  4. How to tell a type is signed or unsigned?
    By meili100 in forum C++ Programming
    Replies: 22
    Last Post: 05-08-2008, 08:21 PM
  5. Signed and unsigned
    By alyeska in forum C++ Programming
    Replies: 5
    Last Post: 09-18-2007, 12:27 PM