Primjer bez pokazivača:
#include <iostream>
using namespace std;
// Definisanje strukture
struct Student {
string ime;
int godine;
float ocjene;
};
int main() {
// Inicijalizacija strukture
Student s1 = {"Lazar", 22, 4.5};
// Pokazivač na strukturu
// Student* pokazivač = &s1;
// Pristup podacima pomoću pokazivača
cout << "Korištenje pokazivača:" << endl;
cout << "Ime: " << s1.ime << endl;
cout << "Godine: " << s1.godine << endl;
cout << "Ocjene: " << s1.ocjene << endl;
return 0;
}
Primjer sa pokazivačima:
#include <iostream>
using namespace std;
// Definisanje strukture
struct Student {
string ime;
int godine;
float ocjene;
};
int main() {
// Inicijalizacija strukture
Student s1 = {"Lazar", 22, 4.5};
// Pokazivač na strukturu
Student* pokazivač = &s1;
// Pristup podacima pomoću pokazivača
cout << "Korištenje pokazivača:" << endl;
cout << "Ime: " << pokazivač->ime << endl;
cout << "Godine: " << pokazivač->godine << endl;
cout << "Ocjene: " << pokazivač->ocjene << endl;
return 0;
}