Saturday 19, April 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 GoogleSecrets TipsandTricks Ebook GoogleSecrets TipsandTricks
   
Download How to Avoid Success at all costs Ebook How to Avoid Success at all costs
   
Download PDQCash Ebook PDQCash
   
Download 5 Tips for successful Small Business Marketing Ebook 5 Tips for successful Small Business Marketing
   
Download Marketing Tips Volume 3  Ebook Marketing Tips Volume 3
   
     
Studiesinn.com 2014 All Rights Reserved.
 
Website Designed & Developed by TechXprtz