Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Palash Bauri 👻
Palash Bauri 👻

Posted on • Edited on

     

Baby Steps In C Programming

.

C is one of most used Programming language till date. It is one of the most powerful language and mother of many modern Programming language (eg. Python , Ruby)

🍭 C is a compiled language, unlikePython orRuby , C programs must be translated from human readable code to machine readable code.

The program which translates human readable C code to machine readable code is called a compiler

You'll be Astonished to know that the mostCompilers of C (eg. GCC) is also written in C

You'll find people who says , C is so hard but i say nothing is hard it just needs a good teacher to explain everything.

So without further talking let's take our first step in the world of C Programming.

Setting Up Workspace

As i mentioned earlier C is a compiled language so you need a compiler such as GCC to compile C programs.

Today we'll be using Repl.it to compile and Run C programs online.

If You want to run and compile C Programs in Your local deviceRead This Article

To Run and Compile C programs online without installing anything , UseREPL.it

When Opening Repl.it you'll see a sample program is already written in the left pan. Clear it first.

Writing Traditional Hello World

As I mentioned earlier Hello World is traditional program which every programmer Writes at first when learning new language. Which just printsHello World text in a console window

Hello World program in C is a bit longer than Python or Ruby.

Let's Write

#include<stdio.h>intmain(){printf("Hello World\n");return0;}
Enter fullscreen modeExit fullscreen mode

Write the above code in the left pane of repl.it or if using Local device , write the above script in a file calledhello.c and execute the command in terminal

gcc -o hello hello.c

If you're in repl.it click the *Run * button and if on local device execute this command

./hello if on a linux or Mac Device
Or
hello on MS Windows Device

If everything is fine, you'll see aHello World text in console/terminal

If there's any problem, feel free to let me know in the comments bellow 👇

Otherwise Let's Go To The Next Chapter

Understanding The Hello World Program

Writing code without understanding it is really useless. Copying-Pasting will not work forever.
So, Let's Try to Understand The Above Code.

Let's Try To Understand From First Line

#include<stdio.h>
Enter fullscreen modeExit fullscreen mode

It includes instructions for C compiler and the definition ofprintf , this is like a dictionary for a C Compilers, from this Compilers know what to do withprintf

Let's Step in the next line, We'll find this,

intmain()
Enter fullscreen modeExit fullscreen mode

int is the acronym of integer

heremain() is a function , everything inside a function is taken as a instructions , from this our program knows what to do. There may be other functions , butmain() is a special function , in every program this function is executed first.

And this() parentheses help Compilers identify that it is a function.

Functions are like a jar which contains some special instructions of what to do.

In the next line we'll find{ a curly brace , it denotes the begining of a function , it's like a the lid of a jar.

In the next line we'll find

printf("Hello World");
Enter fullscreen modeExit fullscreen mode

printf is a also like a function but pre-defined , things inside its quotation marks will be written in. Console window when we'll run our program.

Parentheses() denotes the begining and ending of theprintf function

We see a Text ,Hello World\n inside quotation marks this is the text which will be written in console window and at the end there's a\n which tells our program to start a new line and put the cursor in the new line.

Try changing the text and running it

Actually it's not necessary but it is necessary when working with a program which needs to print two or more lines. But you should keep it as a good practice.

You'll see a semicolon; at the end of line, it's not for style, it's necessary , it helps compiler to understand that this line has ended now.

in the next line we'll find

return0;
Enter fullscreen modeExit fullscreen mode

which is not actually for us , but for machine it returns 0 to the machine, and that's how machine understand that the program ran successfully and now ending.

If a program returns a number other than, Computer will think that it has not run successfully. Try Changing it and running it.

And finaly at the end ,} ending curly brace denotes that our main function is ended.

Must Read This Comment :https://dev.to/tux0r/comment/4o9i


So guys that's for now, if you've any questions or got any problems please let me know in the comments below 👇


If You Like My Work (My Articles, Stories, Softwares, Researches and many more) ConsiderBuying Me A Coffee ☕ 🤗

Top comments(7)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
kip13 profile image
kip
404 bio not found ... yet
  • Joined
• Edited on• Edited

mother of many modern Programming language (eg. Python , Ruby)

I think him is refer to the main and first interpreters written in C:

Python ->CPython
Ruby ->Ruby MRI,YARV

CollapseExpand
 
tardisgallifrey profile image
Dave
Just an old BASIC and C programmer trying to learn new things. Interested in C#, Perl, Python, and SQL.
  • Location
    Dallas
  • Education
    MEd
  • Work
    Plant operator/engineer at a hospital
  • Joined

I was able to follow your instructions in the article and got the program to compile correctly on Repl.it. Thanks for that bit of info. I am always looking for a good way to practice online.

Keep going. Keep writing. Keep learning. I liked the article.

Thanks,

CollapseExpand
 
bauripalash profile image
Palash Bauri 👻
Your Friendly Neighbourhood 👨‍💻 Scientist , 🛠 Inventor, 📝 Writer.2018 Google Code-in Finalist , Story Writer.Doing Some 🔭 Radio Astronomy.
  • Email
  • Location
    India
  • Education
    Bachelor's Of Arts, English; NSOU, India
  • Joined

Thank You For Pointing my faults, i learnt a lot.
Thank You.

I'll fix it but for now i think it would a good idea to unpublish it.

 
bauripalash profile image
Palash Bauri 👻
Your Friendly Neighbourhood 👨‍💻 Scientist , 🛠 Inventor, 📝 Writer.2018 Google Code-in Finalist , Story Writer.Doing Some 🔭 Radio Astronomy.
  • Email
  • Location
    India
  • Education
    Bachelor's Of Arts, English; NSOU, India
  • Joined

Must Read This Comment :dev.to/tux0r/comment/4o9i

I added this line in the post.

CollapseExpand
 
ravi-prakash-singh profile image
Ravi Prakash Singh
GPU Compiler Engineer and Vulkan Programmer.
  • Location
    Delhi, India
  • Education
    Senior High School
  • Pronouns
    He/His/Him
  • Work
    Software Engineerr
  • Joined

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Your Friendly Neighbourhood 👨‍💻 Scientist , 🛠 Inventor, 📝 Writer.2018 Google Code-in Finalist , Story Writer.Doing Some 🔭 Radio Astronomy.
  • Location
    India
  • Education
    Bachelor's Of Arts, English; NSOU, India
  • Joined

More fromPalash Bauri 👻

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp