DEV Community

Discussion on: Part 1: Hello World! , Variables and Data types

Collapse
 
pauljlucas profile image
Paul J. Lucas • Edited

Your example:

cout<<"Hello World!";
Enter fullscreen mode Exit fullscreen mode

is missing the \n at the end, so, in a Unix shell, it will print that immediately followed by the shell's prompt — not what you want.

The value “1” shows that the program has failed to execute.

No; any non-zero value does that; but there are typically OS-specific range limits, typically in the range –127 to 128. Also, the program did execute: it just encountered some error while executing.

There should be no spacing.

No, there must be no spacing.

Do not start your variable names with an underscore.

You only shouldn't do that in the global namespace. See here for the complete rules regarding identifier naming.

You omit short, long, and all the unsigned variants.

Global variables have their scope throughout the program as they can be accessed anywhere in the program.

No, a variable at file scope having external linkage is accessible throughout the program. A variable declared static at file scope is not available outside that file.

The sizes of data types you give are wrong. C++ does not mandate any particular maximum size for any data type. All C++ guarantees is that:

1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
Enter fullscreen mode Exit fullscreen mode

See here for complete details.