This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Where does ‘Hello world’ come from?
"Hello world!" is the most commonly used example I can think of, yet I don't really know where it came from. Was it used by some particular book, or did it just spread among developers? Did people write "Hello world!" snippets in COBOL or FORTRAN ?
Just a quick search on wikipedia gaves :
http://en.wikipedia.org/wiki/Hello_world_program#History
The first known instance of the usage
of the words "hello" and "world"
together in computer literature
occurred earlier, in Kernighan's 1972
Tutorial Introduction to the Language
B
Related
This question already has answers here:
can i use c++ compiler to compile c source code? [duplicate]
(3 answers)
What is the difference between g++ and gcc?
(10 answers)
Closed 2 years ago.
It's what I believe to be a very simple question.
Context: I'm following a tutorial that allows me to run C++ code in Visual Studio Code, but I'm trying to run C code, not C++ code. The program I'm trying to run is a simple Hello World program (shown below), but this question applies to all C code.
#include <stdio.h>
int main() {
printf("Hello World!")
}
C and C++ are different languages. And even though they share a similar syntax, the semantic meaning of certain constructs are different.
C++ incorporates a large part of C, but it also diverges. You cannot just assume that C code compiled as C++ will give the same result.
You can write code that is both valid C and valid C++ yet mean different things in the two languages.
While C++ can be seen for the most part a superset of C, there are some constructions that are invalid C++ and others that have different behavior.
Instead of dealing with that, tell your compiler to target C instead of C++. All the popular C++ compilers also support C (at least one version).
This question already has answers here:
Is it legal to recurse into main() in C++? [duplicate]
(5 answers)
Closed 7 years ago.
Can I call the main method in C/C++ from other functions. it seems to work but I do not know if it is a good software design in c++. please tell me the pros and cons ?
Thank you.
In C you can. In C++ you can't.
Quoting the C++ standard (§3.6.1.3):
The function main shall not be used within a program.
There's nothing in the C standard forbidding calling main.
Whether or not calling main is good design is quite opinion-based, but usually one would be better off using a loop instead.
According to C++ standard
5.2.2.9 "Recursive calls are permitted, except to the function named main"
You've already determined it is possible. However, it makes your entire program recursive. It also could make your code a little harder to understand.
So it's really hard for me to imagine any pros for this.
This question already has answers here:
Capturing a keystroke in C++
(4 answers)
Closed 9 years ago.
I am trying to use keystrokes to affect my program. For example, I have a program that prints numbers continuously. I want it to stop printing numbers if I enter Ctrl+E. How can I do this on C++?
I have read about a number of headers like conio.h but they are not built in the C library. I would like this to be kept as pure C/C++ as possible.
you can use GetAsyncKeyState function for this.
It is there in Winuser.h file
That depends on the operating system - hence impossible in 'pure' C/C++.
I fear you have to go with #ifdef SYSTEM_A, ...
Please notice, The languages C/C++ are not aware of any kind of hardware (keyboard in this case), they know streams.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Hide console in C system() function, Win.
Hi guys I have a little problem, I need to ping a lot of PC, so in my program i call the function system() with "ping -n 1 > tmp.txt", but I don't want that the console window is shown.
How can I do it?
P.S.: I use dev c++ :D
thx
It is fairly hard to do this cleanly.
A better approach might be to google "ping.c" and choose one of the many implementations, then rip the guts out of it and make your own ping function. This will be faster and give you more control.
I found what you might be looking for here Hide a window in C++
And also here I guess the freeconsole() method is what you are needing?
See this question :
Hide console in C system() function, Win
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Code convert from C++ to C
Two months ago, my instructor have asked one question, I have searched to looking for answer but I could not find it.
question :
From c++ code, how can one generate c code just using console ( with g++ ) .
How can I do this ?
g++ compiles C++ directly to machine code, it does not first compile to C then compile that.
There may be some compilers that compile to C code first. I do not know of any if you really need the code. It is not the most efficient way to do it though.
I think that is what your instructor was trying to ask you, i.e. if there is a compiler switch to generate C code.
Is there any particular reason why you need to generate C code. Creating a C interface can be useful and there are ways to do this.
I'm far from a GNU expert, but I belive the compiler option would be -std=C89, to enforce compilation to follow the C90 version of the C standard (equivalent to old "ANSI C" which was released in 89, hence the C89), or -std=C99 for the C99 version of the standard.