is the following c++ code for printing the ASCII value of a number correct?

 void main()
{ int a=10;
 char ch[10];
4 Years
Discussion Span
Last Post by Tumlee

No, the code is not correct at all.

It's not supposed to be <iostream.h> , it's just supposed to be <iostream> .

You shouldn't be using <conio.h> at all, because that just allows you to use old DOS-isms that can be done in a more portable way.

You're not supposed to use void main() , you are supposed to use int main() . Furthermore, you are supposed to have return 0; at the end of your program, not the ancient and deprecated getch(); .

The line ch=a; will immediately cause a compiler error because ch is a static array, and that line of code is an attempt to change its location (which is illegal). You don't even need an array in this case anyway. Actually, you don't even need the variable a .

I'm pretty sure you need to have using namespace std; before the main() if you want to be able to use cout .

If you want to print the a character based on the ASCII value with cout , the following is sufficient:

#include <iostream>

using namespace std;

int main()
    char ct = 10;    //Replace the number 10 with whatever the ASCII value is.
    cout << ct;

    return 0;
This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.