0

I wanna print ascii value of character just look and think about code that why this code shows output 0 for all char type value

#include <iostream> using namespace std; void function(int value) { cout<<value; } int main() { int value; cin>>value;//input char type function(value); }

10th Dec 2019, 3:54 PM
Yash Kumar Tolkar
4 Réponses
+ 2
Change the type for variable <value> from `int` to `char`. Make the change in both main and `function` function. You are getting zero because input failure while trying to read a char as int, and input stream set the <value> variable to zero.
10th Dec 2019, 4:05 PM
Ipang
+ 1
I already mentioned why in my second paragraph. The input given is a character while the <value> variable is an int variable, and so an int was expected. The input stream is unable to use and store the character input into <value> variable because the input type was unexpected.
10th Dec 2019, 4:38 PM
Ipang
+ 1
Thanks
10th Dec 2019, 4:51 PM
Yash Kumar Tolkar
0
Why this shows only 0 not any other output this is my question?
10th Dec 2019, 4:23 PM
Yash Kumar Tolkar