C Programming for Beginners : Circumference and Area of Circle

Suraj Das
4 min readOct 25, 2021

--

Photo by Scott Graham on Unsplash

Prerequisites

VS Code Settings

For building a program which can calculate the circumference and area of a circle, the program would be needing some input from the user.
For that, we have to change some settings so that we can get access to user input.

Run Code in Terminal

  • Open settings by pressing Ctrl + ,
    (control + comma)
  • Search for “terminal
  • You can see at the bottom of the left side; Run Code configuration. Click on that!
  • Make sure to check the Run In Terminal option.

Great! Now we are good to go.

The ‘Address of’ Operator : &

Definition

An address-of operator is a mechanism within C that returns the memory address of a variable.

Example

Output :

000000000061FE1C

This is the address of x in the memory.

(This memory address can be different for different compilers.)

Breakdown of the Code

Here we created a variable named x which is an integer type.
Now this variable x has acquired some memory.

But where exactly is this x stored in the memory ?
We have to get the address of x in the memory.

Ignore the %p format specifier for now. It will be explained later in detail. Our main focus was to print the address of x somehow.

The &x basically tells Address of x. Always read & as “address of”.

User Input with Scan Function

Here is a program where you can enter your lucky number as input and it will print the output according to the input.

Output :

Enter your lucky number :

Type your number and hit enter

Enter your lucky number : 7
Okay! So your lucky number is 7

Breakdown of scanf()

The Scan function takes input from us.

Syntax :
scanf(type, address_of_variable)

Note : The placeholder should match the variable type.

Don’t panic if you can’t understand at first. Read the code again and it will make sense eventually.

Yayy! Now, we’ve learnt enough to make the program.

Circle Circumference and Area Program

Read the program only once (but carefully) and try to build it on your own.
Don’t be afraid to make errors.
Trust me! You will learn more by making errors.

A quick question for you :

The scanf() holds a placeholder of a double type. What is the reason ?
Comment down the answer :)

Outro

Hurray! You’ve now completed a good beginner friendly project.

Have any doubt ?
DM me on Instagram

Peace.

Index of C Programming lessons :

  1. Getting Started within 5 minutes
  2. Learning Fundamentals Made Easy
  3. Circumference and Area of Circle
  4. scanf() vs fgets()
  5. Hypotenuse Calculator
  6. Learn by Building a Calculator
  7. Functions
  8. More on Functions
  9. Length of an Array
  10. String Functions
  11. The While Loop

--

--