Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
C Program For Hexadecimal to Decimal Conversion
Next article icon

C Program For Int to Char Conversion

Last Updated : 08 May, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

To convert the int to char in C language, we will use the following 2 approaches:

  1. Using typecasting
  2. Using sprintf()

Example:

Input:  N = 65 Output: A

1. Using Typecasting

Method 1:

  • Declaration and initialization: To begin, we will declare and initialize our integer with the value to be converted.
  • Typecasting: It is a technique for transforming one data type into another. We are typecasting integer N and saving its value in the data type char variable c.
  • Print the character: Finally, print the character using print.

Example:

C




// C program to demonstrate
// conversion of int to char
// using typecasting
#include <stdio.h>
 
// Driver code
int main()
{
    int N = 103;
    printf("%c", (char)(N));
    return 0;
}
 
 
Output
g

Time complexity is O(1)

The auxiliary is also O(1)

Method 2:

  • Declaration and initialization: To begin, we will declare and initialize our integer with the value to be converted.
  • Typecasting: Declare another variable as character c and assign the value of N to the C
  • Print the character: Finally, print the character using printf.

Example:

C




// C program to demonstrate conversion of
// int to char using typecasting
#include <stdio.h>
 
// Driver code
int main()
{
    int N = 71;
    char c = N;
    printf("%c", c);
    return 0;
}
 
 
Output
G

2. Using sprintf()

Allot space for a single int variable that will be converted into a char buffer.

Example:

C




// C program to demonstrate conversion of
// int to char using sprintf()
#include <stdio.h>
int main()
{
    int num = 71;
    char c[1];
 
    sprintf(c, "%c", num);
    printf("The character value is %s", c);
 
    return 0;
}
 
 
Output
The character value is G

Method: Converting to int to char by adding 0 

C




#include <stdio.h>
 
// Driver code
int main()
{
    int N = 71;
    char c = N+0;
    printf("%c", c);
    return 0;
}
 
 
Output
G

Method:

C




#include <stdio.h>
 
int main()
{
    int num=71;
    if (num >= 0 && num <= 127) {
        printf("The character representation of %d is: %c\n", num, num);
    } else {
        printf("The integer %d is out of range for character representation\n", num);
    }
    return 0;
}
 
 
Output
The character representation of 71 is: G


Next Article
C Program For Hexadecimal to Decimal Conversion

L

laxmigangarajula03
Improve
Article Tags :
  • C Language
  • C Programs
  • C Conversion Programs

Similar Reads

  • C Program For Char to Int Conversion
    Write a C program to convert the given numeric character to integer. Example: Input: '3'Output: 3Explanation: The character '3' is converted to the integer 3. Input: '9'Output: 9Explanation: The character '9' is converted to the integer 9. Different Methods to Convert the char to int in CThere are 3
    3 min read
  • C Program For Long to String Conversion
    To convert the long to string in C language we will use the following 2 approaches: Using Macros with sprintfUsing sprintf Input: long = 1234 Output: string 12341. Using Macros and sprintf C/C++ Code // C Program for Long to // String Conversion #include <stdio.h> #include <string.h> #de
    1 min read
  • C Program For Octal to Decimal Conversion
    The number system is one of the ways to represent numbers. Every number system has its own base or radix. For example, Binary, Octal, Decimal, and Hexadecimal Number systems are some of the number systems and are also used in microprocessor programming. These numbers are easy to convert from one sys
    3 min read
  • C Program to Print Continuous Character Pattern
    Here, we will see how to print continuous character patterns using a C program. Below are the examples: Input: rows = 5Output: A B C D E F G H I J K L M N O Input: rows = 3Output: A B C D E F There are 2 ways to print continuous character patterns in C: Using for loop.Using while loop. Let's discuss
    5 min read
  • C Program For Hexadecimal to Decimal Conversion
    Here we will build a C program for hexadecimal to decimal conversion using 5 different approaches i.e. Using format SpecifierUsing Switch caseUsing array Using while loopUsing for loop We will keep the same input in all the mentioned approaches and get an output accordingly. Input:  hexanumber = "2D
    4 min read
  • C Program to Print Contents of File
    C language allows users to process the files in its programs. Reading a file is a step-by-step process in which we first have to prepare the file only after which we can start reading. In this article, we will learn how to read and print the contents of a file using C program. The simplest method to
    4 min read
  • C program to print name pattern
    The printing of patterns is the most common and interesting problem. This C program prompts users to input their names and transform each letter of the name into a visually appealing big star pattern. For Example, Input: NAME Output: * * **** * * ****** ** * * * ** ** * * * * ****** * ** * **** * **
    5 min read
  • Convert String to int in C
    In C, we cannot directly perform numeric operations on a string representing a numeric value. We first need to convert the string to the integer type. In this article, we will discuss different ways to convert the numeric string to integer in C language. Example: Input: "1234"Output: 1234Explanation
    6 min read
  • C Program to Find the Size of int, float, double and char
    Write a C program to find the size of the data types: int, float, double, and char in bytes and print it on the output screen. Examples Input: charOutput: Size of char: 1 byte Input: intOutput:Size of int: 4 bytes Different Methods to Find the Size of int, float, double and char in CWe can find the
    4 min read
  • C Program To Print Continuous Character Pyramid Pattern
    There are 2 ways to print continuous character patterns in C i.e: Using for loopUsing while loop Input: rows = 5 Output: A B C D E F G H I J K L M N O1. Using for loopApproach 1: Using CharacterAssign any character to one variable for the printing pattern. The first for loop is used to iterate the n
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences