CPP Structs

Structs are blueprints in CPP. Like classes, CPP structs are used to create instance of a class, but are preferred only for lightweight objects which are not intended to any future modifications. The lightweight objects include, Rectangle, color, Point etc. A CPP class uses Call by Value method for calling while, CPP structs uses Call by Reference method for calling.


#include <iostream.h>  
using namespace std;  
struct Sphere  
int radius;    
int main()
struct Sphere circle;  
cout<<"Area of Sphere is: "<<(4*3.14* circle.radius*circle.radius)<<endl;  
return 0;  


Area of Sphere is: 803.84
Please follow and like us:
Content Protection by DMCA.com