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); }
4 odpowiedzi
+ 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.
+ 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.
+ 1
Thanks
0
Why this shows only 0 not any other output this is my question?