September 20, 2022

CurledMark

curled up on the sofa

Fundamentals of C Programming

This is the first topic of C programming which is the Fundamentals of C Programming. Like any other programming language, C is a programming language. With a language, we can write programs. A program is a set of instructions.

We write a program in a file. To create a file we will have to use an editor. Some examples of editors are MSWord, Notepad, and OfficeWriter.

For the execution of the program, we need to provide the name of the program to the Operating System(OS). The OS sends the program to the RAM and then it executes the program. This is the process of execution of any program.

So, what is RAM here mentioned above? RAM is a storage device where the OS sends the program and RAM stores the program. RAM is also called Random access memory.

Introduction to C

We will write a program in a file, for that we can use notepad. To save that file, we will name it with an extension. For example, program1.C

In C, there are multiple functions with unique names, furthermore, a function is a set of instructions.

There should be the main function in a C program.

Main is the entry point function of a program. So the process is like when there is working for the execution of the program, the OS control moves to main first and calls another function(anf). The control goes to anf, executes the contents of anf, and then goes back to main after execution.

OS —————–> main————calls————-> Executes anf——goes back to—————–>main

That is OS starts its execution from the main function which is called the entry function of the program. Other functions get called when we place a call to them. Whenever the function ends, the control goes back to the function, from where it was called.

Syntax of the functions

C language is a case-sensitive programming language. There is the syntax to write any language so as C has. The syntax is represented in a program named program. C is as follows.


Void function1()

{

//definition of the function

}

int main()

{

//definition of the function

}


[] – square bracket

{} – curly bracket

() – round bracket

Void and int are the keywords.

How to write a C program?

Write a program to compute the sum of 10 and 20. Also, print the sum on the monitor.

Ex- x=10, y =20, z= x+y where x,y, and z are the variables. + and = are the operators.

Rules to writing a program

  1. All the variables used within a function should be declared at the start of the function.
  2. To declare means to specify the type of data or information a variable is supposed to store.
  3. All the statements within a function should end with a semicolon(;)

Note: What will OS do?

OS will allocate memory for x,y, and z in RAM.

Compilation and execution

Keywords to declare a variable

integers – long int – %d,

decimals – double float – %f,

character – char -%c where %d,%f, %c are the format specifiers.

The “printf” function is a predefined function that is capable of printing a string where the String is a collection of characters. We can call printf to print something on the monitor.

OS does not understand the English language so here is an introduction to Compiler which acts as a translator and produce a compiled code/executable file. Note: For every programming language there is a separate compiler.

How does the compiler work?

The compiler will check the source code for correctness. If the code is incorrect it will print an error message or if the code is correct the compiler will compile the source code and will produce an executable file/compiled code. So program1.C will be saved as program1.exe.

The compiler does not have any idea about Predefined functions, here it is printf. So for the compiler to know the functionality of printf or any predefined function, it has to know about the syntax of placing a call to printf function.

For this, there are header files. The header file is a prototype of functions related to standard input-output. “stdio.h” is one of the header files.

Fundamentals of C
Program Code

So we write this at the start of the program:

#include<stdio.h> where #(hash) is the preprocessor directive to the compiler.

The Compiler will scan from the first to the last line and will produce an executable file. Then there happens the distribution of execution.


Program name: program1

#include<stdio.h>

int main()

{

int x,y,z; //declaration of variables

x=10; //assignment of 10 to x

y=20; //assignment of 10 to y

z=x+y; //assignment of the sum of values of x and y to z

Printf(“Total is %d”,z); //to print on the monitor screen

return 0; //end of main function

}

Output on the monitor screen:

Total is 30


Conclusion

This is the first chapter of C programming. You will get a complete course for C as soon as possible. Stay tuned!

Also read,

7 Effective Ways to get traffic to your blog

Perfect

How to host a WordPress website in AWS for free 

How to launch EC2 instance in AWS

7 tips for effective technical writing

Flawed

The Last Lecture

Factfulness

ERP VS. EPM

Spark

Willpower

The Power Of Silence

How to Learn Anything

The Ultimate Revelation of How Not to Get Tired in a Day

How to host a WordPress website in AWS

How to launch EC2 instance

Corporate Chanakya

Scrum

Sunk Fallacy

The Zahir

Sprint Book

The Power of Patience

The Unfair Advantage

The Power of Now

Time Management Ninja Book

Learn Better

Emotional Intelligence

48 Laws of Power

Financial Freedom

Still Me

Think and Grow Rich

Make Time

So good they can’t ignore you

You are a Badass At Making Money

Man’s Search For Meaning

The Great Gatsby

The Forty Rules of Love Summary

The Norwegian Wood by Murakami Summary

Relentless Summary

The Da Vinci Code by Dan Brown Summary

The Book Of Five Rings Summary

The Blue Umbrella

How to Talk to Anyone by Leil Lowndes

Jonathan Livingston Seagull Book Summary

Your Brain on PORN Book Summary by Gary Wilson

THE IMMORTALS OF MELUHA By Amish Tripathi full summary

Eleven Minutes by Paulo Coelho Summary

Hyperfocus by Chris Bailey Summary