Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C
Expertise: Beginner
Oct 3, 2003

Constructors of Built-in Types

The way we have constructors for user defined data types, we also have constructors for built in data types like chat, int, float and so on. Here is a program that demonstrates this:

#include <iostream.h>

int main()
{
   int i1=int();
   int i2=int(5);
   char c1=char();
   char c2=char('F');
   float f1=float();
   float f2=float(3.29);

   cout<<"int()->"<<i1<<endl;
   cout<<"int(5)->"<<i2<<endl;

   cout<<"char()->"<<c1<<endl;
   cout<<"char('F')->"<<c2<<endl;

   cout<<"float()->"<<f1<<endl;
   cout<<"float(3.29)->"<<f2<<endl;

   return(1);
}

output:-


int()->0
int(5)->5
char()->
char('F')->F
float()->0
float(3.29)->3.29
Rajashekar Narla
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date