Bài viết được sự cho phép của tác giả Trần Hữu Cương
Từ khóa (keyword) trong C
Từ khóa là các từ được định nghĩa sẵn trong ngôn ngữ C, mang một ý nghĩa nào đó. Không thể dùng từ khóa để làm định danh, tên biến hay hằng số.
C gồm 32 từ khóa:
auto |
double |
int |
struct |
break |
else |
long |
switch |
case |
enum |
register |
typedef |
char |
extern |
return |
union |
const |
float |
short |
unsigned |
continue |
for |
signed |
void |
default |
goto |
sizeof |
volatile |
do |
if |
static |
while |
Từ khóa trong C++
Ngoài những từ khóa trong C thì C++ còn bổ sung thêm một số từ khóa khác như
true |
false |
private |
protected |
public |
try |
catch |
dynamic_cash |
reinterpret_cast |
static_cast |
const_cast |
throw |
explicit |
new |
this |
asm |
operator |
namespace |
typeid |
typename |
class |
friend |
template |
using |
virtual |
delete |
inline |
mutable |
wchar_t |
bool |
And |
bitor |
not_eq |
xor |
and_eq |
compl |
or |
xor_eq |
bitand |
not |
or_eq |
export |
explicit |
|
|
Ngoài ra, C++ vẫn còn một số từ khóa khác được bổ sung các version mới ví dụ:
alignas (since C++11) |
alignof (since C++11) |
and |
and_eq |
asm |
atomic_cancel (TM TS) |
atomic_commit (TM TS) |
atomic_noexcept (TM TS) |
auto(1) |
bitand |
bitor |
bool |
break |
case |
catch |
char |
char16_t (since C++11) |
char32_t (since C++11) |
class(1) |
compl |
concept (since C++20) |
const |
constexpr (since C++11) |
const_cast |
continue |
co_await (coroutines TS) |
co_return (coroutines TS) |
co_yield (coroutines TS) |
decltype (since C++11) |
default(1) |
delete(1) |
do |
double |
dynamic_cast |
else |
enum |
explicit |
export(1) |
extern(1) |
false |
float |
for |
friend |
goto |
if |
import (modules TS) |
inline(1) |
int |
long |
module (modules TS) |
mutable(1) |
namespace |
new |
noexcept (since C++11) |
not |
not_eq |
nullptr (since C++11) |
operator |
or |
or_eq |
private |
protected |
public |
register(2) |
reinterpret_cast |
requires (since C++20) |
return |
short |
signed |
sizeof(1) |
static |
static_assert (since C++11) |
static_cast |
struct(1) |
switch |
synchronized (TM TS) |
template |
this |
thread_local (since C++11) |
throw |
true |
try |
typedef |
typeid |
typename |
union |
unsigned |
using(1) |
virtual |
void |
volatile |
wchar_t |
while |
xor |
xor_eq |
|
Okay, Done!