📄 pr06017.cpp
字号:
////////////////////////////////////////
// File Name: pr06017.cpp
////////////////////////////////////////
#include <iostream>
#include <cstdlib>
// Employee record structure.
struct Employee
{
short int emplno;
char* name;
float salary;
};
// Function prototypes.
void ShowEmployee(const Employee* emp);
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
Employee* emp;
// Allocate memory for an employee record.
// The function malloc() returns a void pointer,
// but the program casts the pointer to Employee*.
emp = (Employee*) std::malloc(sizeof(Employee));
// If the allocation was successful...
if (emp != 0)
{
// Build an Employee record.
emp->emplno = 123;
emp->name = "Jones";
emp->salary = 37500;
// Show the record.
ShowEmployee(emp);
// Free the memory allocated to the record.
std::free(emp);
}
return 0;
}
////////////////////////////////////////
// Display an Employee record.
////////////////////////////////////////
void ShowEmployee(const Employee* emp)
{
std::cout << "Empl#: " << emp->emplno << std::endl;
std::cout << "Name: " << emp->name << std::endl;
std::cout << "Salary: " << emp->salary << std::endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -