Skip to content

Instantly share code, notes, and snippets.

@gbrigens
Last active January 26, 2022 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbrigens/fdc9e004e0852eec8da42e03810fe872 to your computer and use it in GitHub Desktop.
Save gbrigens/fdc9e004e0852eec8da42e03810fe872 to your computer and use it in GitHub Desktop.
Pointers in C++
#include <iostream>
#include <string>
using namespace std;
struct Student {
string name;
int id;
int marks[3];
};
// Function prototype for getting details.
void getStudentDetails(Student* studentPointer);
void printStudentDetails(Student* studentPointer, int size);
int main() {
Student studentModel; // instantiating a student obj.
Student* studentPointer = &studentModel; // Define a pointer for the student obj.
// Note: You can send either studentPointer or &studentModel. They both refer to same address.
getStudentDetails(studentPointer); // Get data from the keyboard to instance and print the object.
return 0;
}
// Implement your solution.
void getStudentDetails(Student* studentPointer) {
}
void printStudentDetails(Student* studentPointer) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment