Thursday 21, August 2014
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    About Us    |    Contact Us

Variables in C++

A variable of type char stores a single character, variables of type int store integers (numbers without decimal places), and variables of type float store numbers with decimal places. Each of these variable types - char, int, and float - is each a keyword that you use when you declare a variable.
What's with all these variable types?
Sometimes it can be confusing to have multiple variable types when it seems like some variable types are redundant (why have integer numbers when you have floats?). Using the right variable type can be important for making your code readable and for efficiency--some variables require more memory than others. Moreover, because of the way the numbers are actually stored in memory, a float is "inexact", and should not be used when you need to store an "exact" integer value.
Declaring Variables in C++
To declare a variable you use the syntax "type ;". Here are some variable declaration examples:
 
int x;
char letter;
float the_float;
It is permissible to declare multiple variables of the same type on the same line; each one should be separated by a comma.
int a, b, c, d;
If you were watching closely, you might have seen that declaration of a variable is always followed by a semicolon (note that this is the same procedure used when you call a function).
Common Errors when Declaring Variables in C++
If you attempt to use a variable that you have not declared, your program will not be compiled or run, and you will receive an error message informing you that you have made a mistake. Usually, this is called an undeclared variable.

Example :
#include

using namespace std;

int main()
{
  int thisisanumber;

  cout<<"Please enter a number: ";
  cin>> thisisanumber;
  cin.ignore();
  cout<<"You entered: "<< thisisanumber <<"\n";
  cin.get();
}

 
     
   
C++ Tutorial
 
  Introduction to C++
Introduction to C++
  Variables in C++
Variables in C++
  if statement in C++
if statement in C++
  Looping in C++
Looping in C++
  break & continue statements
break & continue statements
  Switch Case Statement
Switch Case Statement
  C++ Functions
C++ Functions
  Pointers in C++
Pointers in C++
  Arrays in C++
Arrays in C++
  Strings in C++
Strings in C++
  Structures in C++
Structures in C++
  C++ File I/O
C++ File I/O
  Typecasting in C++
Typecasting in C++
  C++ Classes
C++ Classes
  Recursion in C++
Recursion in C++
  Inheritance in C++
Inheritance in C++
  Initilization Lists in C++
Initilization Lists in C++
  Enumerated Types in C++
Enumerated Types in C++
  Templates in C++
Templates in C++
  C++ Preprocessors
C++ Preprocessors
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download How to Succeed in Online Marketing and Sales Because of Proven Techniques Ebook How to Succeed in Online Marketing and Sales Because of Proven Techniques
   
Download How to Pick a Shopping Cart System that Makes You Money  Ebook How to Pick a Shopping Cart System that Makes You Money
   
Download BMA s Internet Marketing Articles Vol I  Ebook BMA s Internet Marketing Articles Vol I
   
Download Income Plan Ebook Income Plan
   
Download HowToBookmarkForFreeTraffic  Ebook HowToBookmarkForFreeTraffic
   
     
Studiesinn.com 2014 All Rights Reserved.
 
Website Designed & Developed by TechXprtz