65e19d10d9463OOP LAB 1
65e19d10d9463OOP LAB 1
LAB MANUAL # 1
Definition:
A structure is a user-defined data type that allows you to group together variables
of different data types under a single name. Structures provide a way to represent a
composite object that can contain members with various data types.
firstName (string)
lastName (string)
age (integer)
address (string)
Example:
struct Person {
string firstName;
string lastName;
int age;
string address;
};
Example:
Person person1 = {"John", "Doe", 30, "123 Main St."};
Print the values of the structure members to the console.
Example:
cout << "First Name: " << person1.firstName << endl;
cout << "Last Name: " << person1.lastName << endl;
cout << "Age: " << person1.age << endl;
cout << "Address: " << person1.address << endl;
struct Student {
return 0;
string name;
}
int rollNo;
float marks;
};
int main() {
Student s1;
s1.name = "John Doe";
s1.rollNo = 123;
s1.marks = 85.5;
Example:
#include <iostream>
using namespace std;
int main() {
int num = 10;
int *ptr; // Pointer declaration
return 0;
}