G
George
Hello to everybody,
The following code works properly,
but what's the hint with the Dynamic Memory Allocation ???
If i don't specify the ammount of memory that i wish to
allocate (f.e.10), this programm won't work.
So how can we say that "malloc" is used
for dynamic memory allocation ???
I appreciate any help/explanation
Many thanks in advance......
#include <iostream>
using namespace std;
int main()
{
char* name;
name=(char*)malloc(sizeof(char)*10);
if (!name)
{
cout << "Memory Allocation Error.";
exit (0);
}
cout << "Enter your name:";
cin >> name;
cout << "Your name is :" << name;
getchar();
return 0;
}
The following code works properly,
but what's the hint with the Dynamic Memory Allocation ???
If i don't specify the ammount of memory that i wish to
allocate (f.e.10), this programm won't work.
So how can we say that "malloc" is used
for dynamic memory allocation ???
I appreciate any help/explanation
Many thanks in advance......
#include <iostream>
using namespace std;
int main()
{
char* name;
name=(char*)malloc(sizeof(char)*10);
if (!name)
{
cout << "Memory Allocation Error.";
exit (0);
}
cout << "Enter your name:";
cin >> name;
cout << "Your name is :" << name;
getchar();
return 0;
}