Open In App

C++ Program to Determine the Unicode Code Point at a Given Index

Improve
Improve
Like Article
Like
Save
Share
Report

Here, we will find out the unicode code point at a given index using a C++ program.

Input: 

arr = "geEKs"

Output: 

The Unicode Code Point At 0 is = 71.
The Unicode Code Point At 1 is = 101.
The Unicode Code Point At 2 is = 69.
The Unicode Code Point At 3 is = 107.
The Unicode Code Point At 4 is = 83.

Approach:

If the array/string value is increased then it is not feasible to declare an individual variable for the index. If the string size is decreased then the fixed variables can give Out of Bound Error. To handle these situations we will use a for loop to traverse the given string and print the corresponding code point.

Example:

C++




// C++ program to demonstrate
// Unicode Code point
// at a given index
#include <iostream>
using namespace std;
 
// Driver code
int main()
{
    // define input array/string
    char arr[] = "GeEkS";
    int code;
 
    // print arr
    cout << " Input String = " << arr;
 
    // execute a loop to traverse the arr elements
    for (int i = 0; arr[i] != '\0'; i++) {
        code = arr[i];
 
   // display unicode code point at i-th index
   cout <<"\n The Unicode Code Point At "<<i<< " is = " << code;
    }
    return 0;
}


Output

 Input String = GeEkS
 The Unicode Code Point At 0 is 71
 The Unicode Code Point At 1 is 101
 The Unicode Code Point At 2 is 69
 The Unicode Code Point At 3 is 107
 The Unicode Code Point At 4 is 83

Time Complexity: O(n), where n is the array size.
Space Complexity: O(1), 


Last Updated : 07 Oct, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads