ccplusplus.com
Learn C, C++ Concepts
Friday, December 9, 2011
structure example in c
/*********************************************************************** * File : structure-test.cpp * Author : Saurabh Gupta * Desc : structure in c * Desc : structure in c++ * Source : saurabhgupta0527.blogspot.com/p/c_15.html * Created : PM 07:04 04 December 2011 * Note : ************************************************************************/ #include
using namespace std; typedef struct { char firstInitial; char middleInitial; char lastInitial; int employeeNumber; int salary; } EmployeeT; int main(int argc, char** argv) { /* * Create and populate an employee. */ EmployeeT anEmployee; anEmployee.firstInitial = 'M'; anEmployee.middleInitial = 'R'; anEmployee.lastInitial = 'G'; anEmployee.employeeNumber = 42; anEmployee.salary = 80000; /* * Output the values of an employee. */ cout << "Employee: " << anEmployee.firstInitial << anEmployee.middleInitial << anEmployee.lastInitial << endl; cout << "Number: " << anEmployee.employeeNumber << endl; cout << "Salary: $" << anEmployee.salary << endl; return 0; } /* * OUTPUT * [sgupta@rhel6x64 cpp]$ c++ structure-test.cpp -o structure-test [sgupta@rhel6x64 cpp]$ ./structure-test Employee: MRG Number: 42 Salary: $80000 [sgupta@rhel6x64 cpp]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment