Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

Useful variable types for programers

 
webmaster forum
vijay12  Offline
Activity
0%
 
Regular Coder
Posts: 67
Topics: 33
January 03, 2009, 11:08:42 AM

hello friends !!!  what are the types of variables useful to programmers ?? Can multiple classes have variables with the same name and if so , what is their  scope ??
« Last Edit: January 03, 2009, 12:25:24 PM by Admin »
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
January 03, 2009, 02:50:39 PM

There are two types of "type" - primitive (e.g. int, char, float. boolean) and objects (e.g string, list, stack) For a full list of objects have a look at java.sun.com/api - allows you to choose the one that you need.

Yes, you can have variables with the same name AS LONG as they do not collide (i.e. are in different scope and do not exist together), you can have global class and local method variables the same name too

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
webmaster forum
cashcars  Offline
Activity
100%
 
Regular Coder
Posts: 74
Topics: 4
WWW
January 15, 2012, 11:37:18 AM

Declaration of variables
In order to use a variable in C++, we must first declare it specifying which data type we want it to be. The syntax to declare a new variable is to write the specifier of the desired data type (like int, bool, float...) followed by a valid variable identifier. For example:

1
2
   

int a;
float mynumber;



These are two valid declarations of variables. The first one declares a variable of type int with the identifier a. The second one declares a variable of type float with the identifier mynumber. Once declared, the variables a and mynumber can be used within the rest of their scope in the program.

If you are going to declare more than one variable of the same type, you can declare all of them in a single statement by separating their identifiers with commas. For example:

     

int a, b, c;



This declares three variables (a, b and c), all of them of type int, and has exactly the same meaning as:

1
2
3
   

int a;
int b;
int c;



The integer data types char, short, long and int can be either signed or unsigned depending on the range of numbers needed to be represented. Signed types can represent both positive and negative values, whereas unsigned types can only represent positive values (and zero). This can be specified by using either the specifier signed or the specifier unsigned before the type name. For example:

1
2
   

unsigned short int NumberOfSisters;
signed int MyAccountBalance;



By default, if we do not specify either signed or unsigned most compiler settings will assume the type to be signed, therefore instead of the second declaration above we could have written:

     

int MyAccountBalance;



with exactly the same meaning (with or without the keyword signed)

electrician perth
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page January 21, 2012, 08:46:36 AM