📅  最后修改于: 2023-12-03 14:39:49.926000             🧑  作者: Mango
In C++, isupper()
is a standard library function defined in the <cctype>
header. It is used to determine whether a character is an uppercase letter or not. This function takes a single argument of type int
, which represents the character to be tested. It returns a non-zero value if the character is uppercase, and zero otherwise.
The syntax for isupper()
function is as follows:
#include <cctype>
int isupper(int c);
The isupper()
function takes a single parameter c
, which is an integer of type int
. It represents the character to be checked.
c
is an uppercase letter, the function returns a non-zero value, which evaluates to true
.c
is not an uppercase letter, the function returns zero, which evaluates to false
.Here's an example that demonstrates the usage of isupper()
function:
#include <iostream>
#include <cctype>
int main() {
char ch = 'A';
if (isupper(ch)) {
std::cout << "The character is an uppercase letter." << std::endl;
} else {
std::cout << "The character is not an uppercase letter." << std::endl;
}
return 0;
}
Output:
The character is an uppercase letter.
In this example, the character A
is passed to the isupper()
function. Since A
is an uppercase letter, the function returns a non-zero value, indicating that it is indeed an uppercase letter.
isupper()
function operates on characters based on the current locale. To make it work on characters independent of the locale, you can cast the character to an unsigned char before passing it to isupper()
function.isupper()
function is undefined if the argument c
is not representable as an unsigned char or equal to EOF.For more information, you can refer to the C++ documentation on isupper().