Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 1.58 KB

hello-world.mdx

File metadata and controls

70 lines (51 loc) · 1.58 KB
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

  1. It is possible to include entire standard library in C++ (it is a feature of g++ compiler) by:
#include <bits/stdc++.h>
  1. 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);
  1. Use of newline \n is faster than endl, because endl always causes a flush operation.

:::