C for Beginners

Iot Lab KIIT
5 min readJul 16, 2022

Introduction

Greetings readers! Welcome to my first blog; in this blog, we’ll look at the most basic programming language of all programming languages, the C language. This blog is the first of a series of blogs that will help you learn C the way I learned it.

Disclaimer: Neither am I a master at the language nor is it the best way to learn it. I just found that out of all the courses I browsed through, this was the way that was the most compatible with me.

Before beginning with C, let’s look at what programming languages are- As we know, computers process everything in binary. Programming languages are a tool for us to bridge that gap. Fret not, we won’t be coding with 0s and 1s, but we’ll use certain specified functions(more about in a bit) that the computer can understand after compiling them.

Body/format of a code

Getting right into it, the most popular/used code that courses use for beginners is

#include<stdio.h>

//first statement

/*second statement

third statement

fourth statement*/

int main()

{

printf(“Hello World”);

return 0;

}

The code written above in a compiler.

Output of the code written above, please note that the statements we wrote won’t be printed, and will only be visible on the code.

so, to break the program down, we’ll go from top to bottom —

#include<stdio.h> -This command is our header file, it’ll include the content of stdio.h in the program. This gives direction to the compiler to modify or include the code in the source code before the execution takes place.

<stdio.h> -This contains the inbuilt functions/operators that we’ll be using, without specifying this our program will not be compiled correctly.

// -This is used to input any one statement at the start of your code.

/* … */ -This is used to input multiple statements at the start of your code.

int main() -This is used to ensure that the user knows the state of the code, i.e. if that code passed or failed.

{ } -These are used to contain the body of the program.

printf(“Hello World”); -This is the body of the code, most/all of what we want the program to do will be included within these brackets.

return 0; -This is included with the ‘int main’ ‘function.’ These form a pair, and have the same function. (The int main () and return 0; may not make much sense, but I’ve tried to explain them to the best of my ability, in short, they have to be included to ensure that the code will work properly.

Functions

That was about the format of a code, now we will take a look at the functions, they are fun part of coding in my opinion. Since we used the printf function first, we will be discussing that first.

printf(“abc … xyz”); — This is the syntax that we use for the print function,

anything between the quotations mark will be printed, or displayed.

There are a couple of more characters that help us in printing, they are known as escape characters. They are as follows -

\n -This helps you with creating a new line, much like how the enter key works in word documents.

An example of the code with \n

The output of the code written above

\t -This helps you with inserting a set amount of spaces, much like how the tab key does in word documents.

An example of the code with \t

The output of the code written above

\b -This helps you edit the last character you wrote.

An example of the code with \b

The output of the code written above

\v -This helps you shift down vertically directly from the point you’re at. (Please note that \v only works in some compilers. an alternate way to use \v is to use \n and spaces.)

An example of the code with \v

The output of the code written above

\r -This helps you with returning to the first character of the print function. (Please note that \v only works in some compilers. An alternate way to use it is to just use \b a certain number of times.)

An example of the code with \r

The output of the code written above

This was all about the print function as of now, in the upcoming blogs, we’ll delve deeper into the print function and other functions. I’d suggest practicing making different patterns with the help of the various escape characters we just discussed. (such as a triangle with asterisks, or your name with asterisks.)

Written By: Nekhil Agarwal

--

--