Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Source Codes E-Books Downloads Contact Us About Us

C++ Tutorial
Introduction to C++
C++ Concepts
A C++ Program
Variables in C++
Operators in C++
Control Statements
C++ Functions
C++ Classes
C++ Objects
Constructors and Destructors
Pointers to the Classes
C++ Overloading
Friend Function
Virtual Functions
Exception Handling in C++
C++ Templates
C++ Summary

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
AJAX Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PHP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
.NET (dotnet)
Microsoft.Net
XML Web Services
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills


Variables in CPP

Previous Next



What is Variable?

Variable is the place to store the piece of information. As one might store the friend's phone number in own memory, we can store this information in the computer's memory. These are the means of accessing the computer's memory.

There are fairly strict rules on how the variables are named which C++ imposes:

  • Variable names should start with the letter.
  • The variable names are case-sensitive (i.e., variable "myNumber" is different from "MYNUMBER" which inturn is different from "mYnUmBeR").
  • Variable names cannot have blank spaces in between.
  • A variable names cannot have the special characters.



Variable types

Variables are of three basic types which are as follows:

  1. int
  2. float
  3. char



Declaring the Variables

Variable type is nothing but a description of the kind of the information a variable will store. Declaring the variable in C++ is simple. Let us say that we want to declare the variable of type int called "myAge". That is to say, Variable myAge will store the integer, Variable myName will store an character, Variable myHeight will store float value. In C++, this is written as shown below:

int myAge;

char myName;

float myHeight;



How to Type Cast the Variable?

In C++ Casting is easy. Let us say that we have used a float variable storing the number like "26.3141885", and we want to have the int storing an integer portion instead of the float. This is done as shown below:

int GetAverage()
{

     // assume that regularAvg and specialAvg store two floats
      float totalAvg = regularAvg + specialAvg;

     // cast totalAvg to an int
      int truncatedAvg = (int) totalAvg;

     // return the truncated value
      return truncatedAvg;
}

The key part to notice here is the line of code which reads int truncatedAvg = (int) totalAvg. What we are doing here is taking the float, totalAverage, that stores some kind of the decimal number (say 82.41832), and getting rid of ".41832" part by casting it to the int. This works since int is the only capable of storing the integers, so it simply stores an integer portion of the totalAvg.




Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previous Next

Keywords Variables in CPP, cpp tutorial, functions cpp, cpp array, cpp c++, variables in c++, php variables, cpp code, cpp example, cpp program, cpp function, variables in python, array variables, sample cpp, algorithm cpp, variables in functions, function variables, cpp dll, cpp h, variables in memory, lib cpp, cpp source, functions variables, visual cpp, cpp library, variables in c#, variables in java


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
AJAX Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PHP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
XML Web Services Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz

Privacy Policy
Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.