title |
---|
Hello world |
We will learn through writing code. It is customary start with "Hello world!" program when learning a new programming language. This program simply prints a message in the terminal indicating the code ran successfully.
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import CodeBlock from '@theme/CodeBlock';
import hello_world_c from '!!raw-loader!/src/c/basics/00-hello-world.c';
{hello_world_c}
import hello_world_cpp from '!!raw-loader!/src/cpp/basics/00-hello-world.cpp';
{hello_world_cpp}
Compile the code:
# in case of C
gcc filename.c
# in case of C++
g++ filename.cpp
It will produce an executable (binary) file named a.out
. We can run the
executable by typing:
./a.out
If you will to name your program something other than a.out
, you can specify
a custom name using -o
flag:
gcc filename.c -o my_program
:::tip
- It is possible to include entire standard library in C++ (it is a feature of g++ compiler) by:
#include <bits/stdc++.h>
- Input and output streams can be made more efficient by including following in the beginning of the (main) program:
ios::sync_with_stdio(0);
cin.tie(0);
- Use of newline
\n
is faster thanendl
, becauseendl
always causes a flush operation.
:::