Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
Created November 24, 2010 11:37
Show Gist options
  • Save drewlesueur/713524 to your computer and use it in GitHub Desktop.
Save drewlesueur/713524 to your computer and use it in GitHub Desktop.
learning c++
#include <iostream>
using namespace std;
typedef struct record{
int key;
int data;
} record;
record* new_record() {
record *ret;
ret = (record *) malloc(sizeof(record));
return ret;
}
record** new_record_array(int len) {
int i = 0;
record** my_list = (record**) malloc(len * sizeof(record));
for (i=0; i < 10; i++) {
my_list[i] = new_record();
my_list[i]->key = i + 100;
}
return my_list;
}
int main() {
record *rec = new_record();
record **arr= new_record_array(10);
int i = 0;
for (i=0; i < 10; i++) {
cout << arr[i]->key << "\n";
}
(*rec).key = 30;
(*rec).data = 25;
cout << rec->data;
cout << arr[0]->key;
cout << "test";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment