Output writing implicit typecasting – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Solved Problem #CPP#3208 siteicon   siteicon   siteicon  

Problem Statement - Output writing implicit typecasting

Write output of the following program if the input given is R

int main()
  char x, y=32;
  cout<<"Input an uppercase alphabet: ";
  char c=x+y;
  int d=x+y;
  cout<<"Output 1 would be "<<c<<endl;
  cout<<"Output 2 would be "<<d<<endl;
  return 0;


TC++ #3208


Run Output

Input an uppercase alphabet: R
Output 1 would be r
Output 2 would be 114

char x, y=32;
Both x and y are character type variables.  32 is stored in y. Although 32 is a number but characters store only ascii numbers against characters. Char storage is nothing but a place to store 8 bit numeric value.

cout<<“Input an uppercase alphabet: “; cin>>x;
Here we collect the value of x. If R is input what actually would get stored would be 82

char c=x+y;
Here x as 82 and y as 32 would be stored making it 114 as stored value but type as char so if c is displayed it would be small r (ascii 114)

int d=x+y;
here storage 114 is done as integer, so if displayed it would be displayed as 114

cout<<“Output 1 would be “<<c<<endl;
cout<<“Output 2 would be “<<d<<endl;
Will display small r (the char form of ascii 114) and 114 the integer form directly.


  • The display of char and int forms in 8 bit form are directly interchangeable as the storage is practically the binary number form only. char display or num display are just way to represent them on screen. This kind of conversion is called implicit conversion.


sunmitra| Created: 30-Jan-2018 | Updated: 14-Dec-2018|

Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues