๐Š๐ง๐จ๐ฐ๐ฅ๐ž๐๐ ๐ž ๐ฌ๐ก๐š๐ซ๐ž๐ ๐ข๐ฌ ๐ค๐ง๐จ๐ฐ๐ฅ๐ž๐๐ ๐ž ๐ฌ๐ช๐ฎ๐š๐ซ๐ž๐! | Shalu Anand

Post

editor-img
Shalu Anand
Oct 8, 2022

๐Š๐ง๐จ๐ฐ๐ฅ๐ž๐๐ ๐ž ๐ฌ๐ก๐š๐ซ๐ž๐ ๐ข๐ฌ ๐ค๐ง๐จ๐ฐ๐ฅ๐ž๐๐ ๐ž ๐ฌ๐ช๐ฎ๐š๐ซ๐ž๐!

with this ,

๐—Ÿ๐—ฒ๐˜'๐˜€ ๐—•๐—ฒ๐—ด๐—ถ๐—ป ๐ฐ๐ข๐ญ๐ก ๐ƒ๐š๐ฒ 2:

๐šœ๐šŽ๐š›๐š’๐šŽ๐šœ ๐š˜๐š ๐šœ๐š‘๐šŠ๐š›๐š’๐š—๐š ๐š–๐šข ๐š”๐š—๐š˜๐š ๐š•๐šŽ๐š๐š๐šŽ ๐š˜๐š ๐š๐š‘๐šŽ ๐™ฒ ๐™ป๐šŠ๐š—๐š๐šž๐šŠ๐š๐šŽ.

media

โžก๏ธ๐„๐๐ข๐ญ๐ข๐ง๐  ๐ญ๐ก๐ž ๐ฉ๐ซ๐จ๐ ๐ซ๐š๐ฆ

Simple text editors include vim or gedit on Linux, or Notepad on Windows. Cross-platform editors also include

Visual Studio Code or Sublime Text.

The editor must create plain text files, not RTF or other any other format.

โžก๏ธ๐‚๐จ๐ฆ๐ฉ๐ข๐ฅ๐ข๐ง๐  ๐š๐ง๐ ๐ซ๐ฎ๐ง๐ง๐ข๐ง๐  ๐ญ๐ก๐ž ๐ฉ๐ซ๐จ๐ ๐ซ๐š๐ฆ

To run the program, this source file (hello.c) first needs to be compiled into an executable file (e.g. hello on Unix/Linux system or hello.exe on Windows). This is done using a compiler for the C language.

See more about compiling

โžก๏ธ๐‚๐จ๐ฆ๐ฉ๐ข๐ฅ๐ž ๐ฎ๐ฌ๐ข๐ง๐  ๐†๐‚๐‚

GCC (GNU Compiler Collection) is a widely used C compiler. To use it, open a terminal, use the command line to

navigate to the source file's location and then run:

gcc hello.c -o hello

If no errors are found in the source code (hello.c), the compiler will create a binary file, the name of which is

given by the argument to the -o command line option (hello). This is the final executable file.

We can also use the warning options -Wall -Wextra -Werror, which help to identify problems that can cause the

program to fail or produce unexpected results. They are not necessary for this simple program but this is way of adding them:

gcc -Wall -Wextra -Werror -o hello hello.c

โžก๏ธ๐”๐ฌ๐ข๐ง๐  ๐ญ๐ก๐ž ๐œ๐ฅ๐š๐ง๐  ๐œ๐จ๐ฆ๐ฉ๐ข๐ฅ๐ž๐ซ

To compile the program using clang you can use the:

clang -Wall -Wextra -Werror -o hello hello.c

By design, the clang command line options are similar to those of GCC.

โžก๏ธ๐”๐ฌ๐ข๐ง๐  ๐ญ๐ก๐ž ๐Œ๐ข๐œ๐ซ๐จ๐ฌ๐จ๐Ÿ๐ญ ๐‚ ๐œ๐จ๐ฆ๐ฉ๐ข๐ฅ๐ž๐ซ ๐Ÿ๐ซ๐จ๐ฆ ๐ญ๐ก๐ž ๐œ๐จ๐ฆ๐ฆ๐š๐ง๐ ๐ฅ๐ข๐ง๐ž

If using the Microsoft cl.exe compiler on a Windows system that supports Visual Studio and if all environment variables are set, this C example may be compiled using the following command

which will produce an executable hello.exe within the directory the command is executed in (There are warning options such as /W3 for cl, roughly analogous to -Wall, etc for GCC or clang).

cl hello.c

โžก๏ธ๐„๐ฑ๐ž๐œ๐ฎ๐ญ๐ข๐ง๐  ๐ญ๐ก๐ž ๐ฉ๐ซ๐จ๐ ๐ซ๐š๐ฆ

Once compiled, the binary file may then be executed by typing ./hello in the terminal. Upon execution, the compiled program will print Hello, World, followed by a newline, to the command prompt.

FOLLOW Shalu Anand :)