Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
CPP All : User Defined Data Types
Concept Learning Code Sheets

Use of typedef – 1 #4341

typedef as replacement for using a friendlier name.

#include <iostream>
typedef double amount;
using namespace std;
int main()
{
amount principal=100.50;
amount term=2.5;
amount rate=5.5;
amount simple_interest=principal*term*rate/100.0;
cout<<"Simple Interest = "<<simple_interest<<endl;
return 0;
}

typedef of a previously defined typedef #4503

second level typedef definition of a previously defined typedef.

#include <iostream>
typedef int score;
using namespace std;
int main()
{
score team1=10,team2=12;
typedef score rank;
rank tr1,tr2;
if(team1>team2) { tr1=1;tr2=2; }
else { tr1=2;tr2=1; }
cout<<"Rank Team 1 = "<<tr1<<endl;
cout<<"Rank Team 2 = "<<tr2<<endl;
return 0;
}

typedef for arrays #4506

understanding how typedef includes array size also while defining type

#include <iostream>
using namespace std;
typedef char arr[5];
int main()
{
arr a={1,2,3,4,5};
int sum=0;
for(int i=0;i<5;i++) sum+=a[i];
cout<<"Array Sum = "<<sum<<endl;
return 0;
}



Code Sheets:3 
Back