CodesJava

Easy learning with example program codes

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.

Example:

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

Output

Area of Sphere is: 803.84
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki