Remember Me
forgot your password?

Typecasting and its importance in C++

Type Casting in C++
Casting means you change the representation of a variable by changing its type to a different one. In order to type-cast a simple object to another you use the traditional type casting operator. For example, to cast a floating point number of type 'double' to an integer of type 'int'.

Type Casting causes the program to treat a variable of one type as though it contains data of another type. Normally, this is used with a collection of pointers (addresses) to specify how to interpret the data. When casting is not used with object pointers, it normally means to simply copy the data between incompatible types without converting the data or flagging an error. The figure lists some examples for type casting of operators.

Format: Type name (Expression);

Let us see the concept of type casting in C++ with a small example:

#include <iostream.h>
void main()
{
int a;
float b,c;
cout<< “Enter the value of a:”;
cin>>a;
cout<< “n Enter the value of b:”;
cin>>b;
c = float(a)+b;
cout<<”n The value of c is:”<<c;
}

The output of the above program is

Enter the value of a: 10
Enter the value of b: 12.5
The value of c is: 22.5

In the above program a is declared as integer and b and c are declared as float. In the type conversion statement namely

c = float(a)+b;

The variable a of type integer is converted into float type and so the value 10 is converted as 10.0 and then is added with the float variable b with value 12.5 giving a resultant float variable c with value as 22.5

Read more on typecasting in C++ visit http://www.studiesinn.com

james edward

Expert in Computer Programming Languages and Web Development and Designing Technologies.

Rate this Article: 0 / 5 stars - 0 vote(s)
Print Email Re-Publish

Add new Comment



Captcha

  • Latest Programming Articles
  • More from james edward

CMS Software Solutions with SepCity

By: Doug Muraski | 22/11/2009
CMS Software Solutions with SepCity. Hosting, software plus so much more.

Advantages of Asp Reporting

By: chaudhary fahim | 21/11/2009
Asp Reporting changed the way real professionals do reporting and present ideas. Learning ASP Reporting can improve your presentation skills dramatically.

Getting Started with Asp.Net Reporting

By: chaudhary fahim | 21/11/2009
An article on how to get started with the Asp.Net software when creating reports You can design and develop presentations with Asp.net reporting.

Asp Net Gauge Control

By: chaudhary fahim | 21/11/2009
Asp net gauge control is a very useful skill in data manipulation. Here's an explanation on the illustrations seen on the Asp net gauge control.

The ASP Gauge: More Than The Usual

By: chaudhary fahim | 20/11/2009
Digital dashboards often have several displayed gauges showcasing different data being monitored. An ASP gauge is one such type of gauge used on an ASP template page. Digital dashboards are tools which show data being monitored for easy referencing and analysis. In this fast paced world, there is a need for such tools in order to manage huge amounts of data simultaneously.

Drivers Installation With WiX

By: Apriorit | 20/11/2009
This article is devoted to the methods of the driver packages installation/uninstallation using WiX. In particular we will discuss the usage of the Microsoft DPInst utility for the installation and removal of the drivers during the Windows Installer package setup, review the principles of DPInst functioning, review the issues with the unsigned drivers installation and learn how to launch multiple MSI installations from already running Windows Installer package setup.

Database design & development in Orange County

By: Mike Nielson | 20/11/2009
The database development solutions are designed to provide the integrity of data along with the security of applications. The database systems are required for effective storage of data and management of data so that the information may be utilized in the software applications. Database development takes place in phases, such as analysis performed by the business analysts based on the requirements collected from clients.

Open Source Application: Distribution Terms

By: Tyler Moon | 20/11/2009
Open source does not only mean accessing the source code. The distribution terms of open-source software must be in terms and agreement with the source code, free redistribution, derived works etc.

Submit Your Articles Free: Signup
Article Categories




Use of this web site constitutes acceptance of the Terms Of Use and Privacy Policy | User published content is licensed under a Creative Commons License.
Copyright © 2005-2008 Free Articles by ArticlesBase.com, All rights reserved. (0.08, 1, w2)