[Dev-C++] Bugs: Unallocated Memory (I wrong!)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Nurhidayat <dh...@ma...> - 2001-09-20 05:46:16
|
Oh..
It's not bug. I forget to write an ampersand in front of pointer variable...
#include <stdlib.h>
#include <stdio.h>
struct mystruct {
char name[8];
int age;
};
int main()
{
mystruct *ptr; //test dynamic allocation
int *page;
ptr = new mystruct; //compiler must allocate memory
page = new int;
printf("Address of name : %p\n", ptr->name); //allocated
printf("Address of age : %p\n", &(ptr->age)); //allocated //
printf("Address of page : %p\n", page); //allocated (for comparison)
//so ...
printf("Enter name:"); scanf("%s", ptr->name); //success
printf("Enter age :"); scanf("%d", &(ptr->age)); //success
delete ptr;
delete page;
system("PAUSE");
return 0;
}
___Nurhidayat___
|