C++ Program to take a value from the user as input any character and check whether it is the alphabet, digit or special character. Using user define functions.

Explanation:

  1. Pass-by-Value (checkCharacterByValue):
    • Function Definition: void checkCharacterByValue(char ch)
    • This function takes the character ch as a parameter by value.
    • It uses isalpha to check if ch is an alphabet, isdigit to check if ch is a digit, or considers it a special character otherwise.
    • The function prints the result directly.
  2. Pass-by-Reference (checkCharacterByReference):
    • Function Definition: void checkCharacterByReference(char ch, string &type)
    • This function takes the character ch by value and a reference to a string variable type.
    • It determines if ch is an alphabet, digit, or special character and sets the type reference variable accordingly.
    • The result is updated through the reference variable.
  3. Main Function (main):
    • The program prompts the user to input a character.
    • It then checks and displays whether the character is an alphabet, digit, or special character using both methods.

Example Outputs:

Example 1:

Input:

  • Character: A

Output:

Example 2:

Input:

  • Character: 9

Output:

Example 3:

Input:

  • Character: @

Output: