Created
November 24, 2010 11:37
-
-
Save drewlesueur/713524 to your computer and use it in GitHub Desktop.
learning c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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