GO Program to find the ASCII value of a character

How to find the ASCII value of a character

Here we are explaining how to find the ASCII value of a character in the Go program. We can use the built-in function fmt.println() to print anything and fmt.scanln() for reading the values. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.

func (r *Reader) ReadByte() (byte, error) 

Here ReadByte implements the io.ByteReader interface.


How to find the ASCII value of a character in the GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to find the ASCII value of a character in the Go language. Here variable ch is used to hold the read character. For reading the character create the reader using NewReader. Read the character as ch, _:= reader.ReadByte(). Finally print the results. Given below are the steps which are used in the Go program. 


STEP 1: Import the package fmt, bufio, os

STEP 3: Create a reader using NewReader as reader := bufio.NewReader(os.Stdin)

STEP 4: Read the character into variable ch as ch, _ := reader.ReadByte()

STEP 5: Print the ASCII value of the character using fmt.printf()


GO Source Code

                                          package main

import (

func main() {

    reader := bufio.NewReader(os.Stdin)

    fmt.Print("Enter any character = ")
    ch, _ := reader.ReadByte()

    fmt.Printf("The ASCII value of %c = %d\n", ch, ch)


Enter any character = j

The ASCII value of j = 106