BrainDump
  Home arrow BrainDump arrow Page 4 - C: Input, Variables, and Data Types
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

C: Input, Variables, and Data Types
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2008-02-04

    Table of Contents:
  • C: Input, Variables, and Data Types
  • Variables
  • Data Types
  • Data Type Modifiers

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    C: Input, Variables, and Data Types - Data Type Modifiers


    (Page 4 of 4 )

    In addition to Data Types, there are also data type modifiers, which are used to...you guessed it genius, modify data types.

    The Short and Long of It

    Short and Long are used to modify the amount of memory a data type uses. It can either be less (short) or more (long). You use data modifiers by preceding the data type with the short or long keyword with the exception of an int, which does not need to follow the keywords. A short typically takes up 2 bytes of memory (less than an integer) and is often used for values ranging from -32768 to 32767.

    Longs on the other hand are either the same size as an integer (4 bytes) or larger (8 bytes). Note that you can also use the unsigned specifier in addition to your data modifier to ensure that the values are positive and never negative. Again, you do not need to write int after this specifier. Here are some examples:


    unsigned short myage;

    short myage;

    long yourage;

    short int myage;

    There are other data modifiers and specifiers, but these will do for now.

    Scope

    While this won't really make sense until future articles, it is important to note that variables have a lifetime (just like your goldfish you flushed down the toilet last night). There are two types of lifetimes for variables:

    Local Variables

    Local variables are declared at the beginning of the block they are going to be used in and can only be used in that block of code. They essentially die after that block, becoming useless to the rest of the program.

    Global Variables

    Global Variables are declared outside of any block and can be used from anywhere in your program, essentially never dying. Some people consider them bad programming practice, as (for example) they are harder to track down should a bug occur, but they definitely serve their purpose.

    Well that is it for this article. We will cover more of the data types and modifiers as time progresses. In the next article however, we will discuss Operators and Assignments, so stick around. Or well...come back often, as you may have to wait a few days and I don't want you just sitting there, messing up my web page.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hey, thanks for stopping by. In this article we talk about C and all the glorious...
     

    BRAINDUMP ARTICLES

    - Making Your First Active X Control in Visual...
    - Codes and Packages in Microsoft Project 2007
    - Windows 7: Rumors and Demos
    - XP SP3 Why Me?
    - Breaking Up Your Work in Microsoft Project
    - Breaking Work into Task-Sized Chunks
    - Putting Microsoft`s Worldwide Telescope Unde...
    - Handling Multiple Contracts with Indigo
    - Cleaning Out Your Data in XP
    - Multiple Service Contracts and Indigo
    - Cleaning Out Your Programs in XP
    - Handling Metadata with Indigo
    - Building Blocks for a WCF Service Web Site
    - Help! I Need Some Remote Assistance
    - Using Service Templates with Indigo





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway