Skip to main content

Enumerated Datatypes AND #define

Ooops..! yes, this is an another post related to OOP.

I feel this is some thing nice. There are situations where we want to introduce new data variables. That's why enumerated data types are used. haha, but this is not like u expect!

Enumerated Datatypes

  • These are user defined datatypes
  • the key-word enum is used
  • syntax is enum var_name{var1,vae2,...,varn};
  • what happens is : var1=0, var2=1, var3=2, var4=3,...
  • try the prog. below in ur cpp compiler.

#define

  • #define key-word is used.
  • Eg: #define x value
  • No ";" is used
  • advantage: for a large program, if we want to alter a constant that is repeatedly used throughout the programme.
  • meaning x can be used insted of value.
For the perfect understanding, please work on the example below.
(Shhhh... it is very simple!)
_____________________________________________

// using enumerated data types, #define

#include<conio.h>
#include<iostream.h>
#define num 60
#define name 0

void main()
{
clrscr();

enum b{q,w,e};

cout<<"num ="<<num<<endl<<"name ="<<name<<endl<<"q="<<q<<"\nw="<<w<<"\ne="<<e<<endl;

getch();
}
____________________________________________

Also note:
  • cout is an output statement
  • endl is used for new line
  • "\n" is also used for new line
If u r with problems/help/comments/corrections, Never Ever forget to share it here! Thank U.

Comments