c++ - Returning a pointer to the youngest student in a dynamic array -


i trying write function iterate through dynamic array holds students records in format:

name id age

once function finds youngest age, return pointer main function , output it.

the problem function of type student, structure; , formatted so:

struct student{ string name; string id; int age; 

};

i struggling return pointer (ptr) , output console, outputting (what think) memory location...

here code far,

any advice helpful.

the structure:

struct student{ string name; string id; int age; 

};

the function call:

cout << "youngest: " << youngest(student_dynamic, sizeof) << endl; 

and function:

    student* youngest(student* s, int size) {     int tempage = 0;     int youngestage = 100;     student *pt = new student;      (int = 0;i < size;i++)     {         tempage = (s+i)->age;          if (tempage < youngestage)         {             youngestage = tempage;             pt->age = youngestage;                   }     }        return pt;  //here trying return pointer outputs youngest age                 //to console window...  } 

update:

this question has been answered 'billy pilgrim'

thankyou advice!

you returning pointer, being printed. should like:

student * s = youngest(student_dynamic, sizeof); cout << "youngest: " << s->name << endl; 

(not sure sizeof is:).


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -