I just want to see my output without using any function e.g. Getch ().
is it possible?
Void main()
{
printf(" hello ");
}
I just want to see my output without using any function e.g. Getch ().
is it possible?
Void main()
{
printf(" hello ");
}
But adding functions is the wrong way to do it anyway.
Every Windows executable (a PE32) contains a flag that describes the subsystem required to execute it. For most programs it will indicate either GUI or textual/console.
There are other subsystems, but I’ll pretend they don’t exist for this answer.
Most C (and C++) programs containing main()
are textual, requiring a Windows Console (or Windows Terminal) to be attached to it when it is executed.
There are two[1] ways for this to happen:
[1] There are more than two ways, but I’ll limit the discussion to those two.
When you run it from the IDE you are getting option 2. The IDE ran your program, Windows helpfully created a console window for you, and when your program terminates Windows cleans up by removing the console window.
There are two ways to fix this without modifying your code:
.exe
is.cmd
and press Enter.example.exe
then I would type example
(with or without the .exe
) and press Enter.exit
and press Enter. The console window will disappear.That’s all there is to it!
Wow this is a boring-looking answer. Sorry about that.
In C you need to flush to the console in order to print. You can do so by adding '\n' (newline) at the end of the string you're printing. Also make sure to use proper indentation. The following code should work:
Void main()
{
printf("hello\n");
}