C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
Why constructor in c++
(q) Why constructor ?
Ans:
Goal of c++ is to create such type of class which is very similar to basic data type like int
char,float etc.
It is possible in basic data type like int,char etc we can initialize the data type at the
time of creation .
Example:
#include
#include
int main()
{
int a=6; //intialization at the time
char b='v'; // of creation
clrscr();
cout<
#include
class country
{
char *name;
long int population;
public:
void getdata()
{
Name=”USA”;
Population=700000000;
}
void display()
{
cout<
#include
class country
{
char *name;
long int population;
public:
country()
{
name="India";
population=1000000000;
}
void display()
{
cout<
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment