CPP program to check that the entered character is small, capital, or a special character

Explanation:

  1. Pass-by-Value (checkCharByValue):
    • Function Definition: char checkCharByValue(char ch)
    • This function receives a copy of the character ch and determines its type.
    • It returns a character indicating the type: ‘s’ for small letter, ‘c’ for capital letter, and ‘x’ for special character.
    • The original variable in main is not affected by this function.
  2. Pass-by-Reference (checkCharByReference):
    • Function Definition: void checkCharByReference(char ch, char &type)
    • This function receives the character ch and a reference to the variable type.
    • It directly modifies the type variable based on the character’s type: ‘s’, ‘c’, or ‘x’.
    • The type variable in main is updated by this function.
  3. Main Function (main):
    • The program prompts the user to enter a single character.
    • It then uses both the pass-by-value and pass-by-reference methods to determine the type of the character.
    • Finally, it prints the results for both methods.

Example Outputs:

Example 1: Small Letter

Input:

  • Character: b

Output:

Example 2: Capital Letter

Input:

  • Character: M

Output:

Example 3: Special Character

Input:

  • Character: @

Output: