Himanshu PTLN
Himanshu PTLN
Submitted by:
HIMANSHU
PATLAN
8721213
2021-2025
I hereby declare that the training report entitled "C language" submitted by me to State
Institute of Engineering & Technology, Nilokheri (Karnal) in partial fulfilment of the
requirement for the award of the degree of B.TECH in ECE is a record of bonafide training
work carried out by me. I further declare that the work reported in this project has not been
submitted and will not be submitted, either in part or in full, for the award of any other degree
or diploma in this institute or any other institute or university.
CERTIFICATE
This is to certify that the above statement made by the candidate is correct to the best
of my knowledge.
Officer In-charge
Electronics and Communication Engineering State Institute of Engineering &
Technology, Nilokheri (Karnal)
ABSTRACT
C is a procedural programming language. It was initially developed by Dennis Ritchie in
the year 1972. It was mainly developed as a system programming language to write an
operating system. The main features of the C language include low-level memory access,
a simple set of keywords, and a clean style, these features make C language suitable for
system programing like an operating system or compiler development.
Many later languages have borrowed syntax/features directly or indirectly from the C
language. Like syntax of Java, PHP, JavaScript, and many other languages are mainly
based on the C language. C++ is nearly a superset of C language (Few programs may
compile in C, but not in C++).
To complete a project the person associated with it must have dedication, patience, focus, planning and skill of
course. With the absence of these attributes either the project never results desired outcome or not completed as
expected. As all, I would like to thank all those who supported fully to make the desired project a running one.
During the course many people supported as a motivator and as a mentor.
I am highly indebted to Internet & Trainer for knowledge which makes me skill for the project. Programming
with C by ANSI C is most useful book and Udemy, C tutorial, Geeks For Geeks are the most supporting
online platform for providing necessary information like what datasets can be used, different methods to solve
errors in coding& also as a support in completing the project.
I would like to express my special gratitude and thanks to my project guide Mr.Shiv Goel for giving me such
attention and time in the institute itself and for providing valuable guidance in every stage for this project work.
And also for providing me different ideas which helps me in project.
Last but not least, we would like to express our deep sense of gratitude and earnest thanks giving to our dear
parents for their moral support and heartfelt cooperation in doing the main project.
Spoken Tutorial is a multi-award winning educational content portal. Here one can learn
various Free and Open Source Software all by oneself. Our self-paced, multi-lingual
courses ensure that anybody with a computer and a desire for learning, can learn from
any place, at any time and in a language of their choice. All the content published on this
website are shared under the CC BY SA license.
Our courses are simple and easy to follow even for a beginner but they also meet the
growing needs of the learner. Our engaging digital content ensures that learning happens
at all levels - Basic, Intermediate and Advanced. Our content mandates side-by-side
practice thereby ensuring that learners are actively learning. Many of the software
taught, are used in various disciplines of Engineering, pure Sciences and several other
Under-Grad and Post-Grad studies, and can be extended to Commerce, Arts and
Management streams as well. Alongside these, there are some courses relevant at School
level, too, which help school students to visualise difficult concepts of Math and Science.
These can also be used by Teachers to prepare lesson plans, explain abstract concepts and
give digital assignments to students.
The learning can happen in an organised manner as well. Faculty in institutes can
organise their batch of students into groups, who will learn a particular software course
for an entire semester. The ST course can be mapped to the Course/Lab manuals and
systematic learning can take place. If the academic timetable permits, then a single
student can learn upto 3 different ST courses in one semester during the designated
academic Lab hours.
End-of-Course online tests and certificates are available for those who wish to test their
expertise in a particular software. These certificates give an edge to students during
placement by increasing their employability potential. For more details, please write to
contact [at] spoken-tutorial [dot] org.
LIST OF FIGURES
Figure.1.1 Layout Of C 15
Program
TABLE OF CONTENTS
The original was still called Programming in C, and the title that covered ANSI C was
called Programming in ANSI C. This was done because it took several years for the
compiler vendors to release their ANSI C compilers and for them to become ubiquitous.
It was initially designed for programming UNIX operating system.
Now the software tool as well as the C compiler is written in C. Major parts of popular
operating systems like Windows, UNIX, Linux is still written in C. This is because even
today when it comes to performance (speed of execution) nothing beats C. Moreover, if
one is to extend the operating system to work with new devices one needs to write device
driver programs. These programs are exclusively written in C. C seems so popular is
because it is reliable, simple and easy to use. often heard today is – “C has been already
superceded by languages like C++, C# and Java.
What is ‘C’?
a) C is a high level structured oriented programming language ,used in
general purpose programming.
b) C works with in built compiler ,convert program to machine coded
language.
c) C is most preferred language for decades now , due to its high
performance , remarkable efficiency and its portability.
d) C is a successor of “ basic combined programming language” (bcpl) called
b language.
1.1 Where is ‘C’ being used?
❖ Earlier the language B was now used for improving the UNIX system. Being a
high-level language, B allowed much faster production of code than in assembly
language.
❖ Still, B suffered from drawbacks as it did not understand data-types and did not
provide the use of “structures”.
❖ These drawbacks became the driving force for Ritchie for development of a new
programming language called C. He kept most of language B’s syntax and added
data-types and many other required changes.
❖ Eventually, C was developed during 1971-73, containing both high-level
functionality and the detailed features required to program an operating system.
Hence, many of the UNIX components including UNIX kernel itself were
eventually rewritten in C.
Hold Tight, because I am going to tell you some exciting real-world applications of C.
1. Operating Systems:-
What is better than writing your own operating system? And yes, with the help of the C
programming language, you can write your own operating system. Windows Kernel,
Linux Kernel and Apple’s OS X kernel are mostly written in C.
2. GUI:-
It stands for Graphical User Interface. The C programming language also helps in
developing popular adobe softwares like Photoshop, Premier Pro, Illustrator etc.
3. Embedded Systems:-
In daily life, we use different embedded systems like coffee machines, microwaves,
climate control systems etc. These all are mostly programmed in C.
4. Database:-
The C programming language helps in developing the popular database management
system, MySQL.
5. Ease of Computation:-
C provides faster computation in programs. The implementation of algorithms and data
structures is swift in C. With the help of C, you can perform high degree calculations
such as MATLAB, Mathematica etc.
6. Gaming:-
C programming is relatively faster than Java or Python. It has been used in various
gaming applications and graphics. C programming language also helps in creating many
popular childhood games like Tic-Tac-Toe, The Snake game etc.
1.4 C Editors
There is even more sophisticated IDE available in the market. But for now, you can
consider one of the following:
● Notepad - On Windows machine, you can use any simple text editor like Notepad
(Recommended for this tutorial), TextPad.
● Netbeans - is a C IDE that is open source and free which can be downloaded
from http://www.netbeans.org/index.html
● Eclipse - is also a C IDE developed by the Eclipse open source community and
can be downloaded from http://www.eclipse.org/
CHAPTER-2
C Environment
2.1.2 C Translator
Three types of translator are there:
● Compiler
● Interpreter
● Assembler
Compiler and interpreter are used to convert the high level language into machine level
language. The program written in high level language is known as source program and
the corresponding machine level language program is called as object program. Both
compiler and interpreter perform the same task but there working is different. Compiler
read the program at-a-time and searches the error and lists them. If the program is error
free then it is converted into object program. When program size is large then compiler is
preferred. Whereas interpreter read only one line of the source code and convert it to
object code. If it check error, statement by statement and hence of take more time.
A compiler is a software that converts programs written in a high level language into
machine language. An interpreter is a software that translates a high level language
program into machine language while an assembler is a software that converts programs
written in assembly language into machine language
2.1.3 Integrated Development Environment(IDE)
The process of editing, compiling, running, and debugging programs is often managed by
a single integrated application known as an Integrated Development Environment, or IDE
for short. An IDE is a windows-based program that allows us to easily manage large
software programs, edit files in windows, and compile, link, run, and debug programs.
On Mac OS X, CodeWarrior and Xcode are two IDEs that are used by many
programmers. Under Windows, Microsoft Visual Studio is a good example of a popular
IDE. Kylix is a popular IDE for developing applications under Linux. Most IDEs also
support program development in several different programming languages in addition to
C, such as C# and C++.
#include tells the compiler to include information about the standard input/output
library. It is also used in symbolic constant such as #define PI 3.14(value). The stdio.h
(standard input output header file) contains definition &declaration of system defined
function such as printf( ), scanf( ), pow( ) etc. Generally printf() function used to display
and scanf() function used to read value.
Let us understand what are local and global variables, and formal parameters
The C compiler recognizes a variable as global, as opposed to local, because its
declaration is located outside the scope of any of the functions making up the program.
Of course, a global variable can only be used in an executable statement after it has
been declared. Hence, the natural place to put global variable declaration statements is
before any function definitions: i.e., right at the beginning of the program. Global
variables declarations can be used to initialize such variables, in the regular manner.
However, the initial values must be expressed as constants, rather than expressions.
Furthermore, the initial values are only assigned once, at the beginning of the program.
2.2.3 Main()
It is the user defined function and every function has one main() function from where
actually program is started and it is encloses within the pair of curly braces. The main( )
function can be anywhere in the program but in general practice it is placed in the first
position. In detail, the JRE consists of various components; these are listed below:
#include<stdio.h>
int main (void)
{
printf ("welcome to c Programming language.\n");
return 0;
}
Output: welcome to c programming language.
CHAPTER-3
3.1 C Identifiers
Identifiers are user defined word used to name of entities like variables, arrays, functions,
structures etc. Rules for naming identifiers are:
1. name should only consists of alphabets (both upper and lower case), digits and
underscore (_) sign.
2. first characters should be alphabet or underscore.
3. name should not be a keyword.
4. since C is a case sensitive, the upper case and lower case considered differently, for
example code, Code, CODE etc. are different identifiers.
5. identifiers are generally given in some meaningful name such as value, net_salary,
age, data etc.
An identifier name may be long, some implementation recognizes only first eight
characters, most recognize 31 characters. ANSI standard compiler recognize 31
characters. Some invalid identifiers are 5cb, int, res#, avg no etc.
3.2 C Keywords
There are certain words reserved for doing specific task, these words are known as
reserved word or keywords. These words are predefined and always written in lower case
or small letter. These keywords cann’t be used as a variable name as it assigned with
fixed meaning. Some examples are int, short, signed, unsigned, default, volatile, float,
long, double, break, continue, typedef, static, do, for, union, return, while, do, extern,
register, enum, case, goto, struct, char, auto, const etc.
3.3 C Operators
An operator is a symbol that tells the compiler to perform specific mathematical or logical
functions. C language is rich in built-in operators and provides the following types of
operators −
● Arithmetic Operators
● Relational Operators
● Logical Operators
● Bitwise Operators
● Assignment Operators
● Misc Operators
We will, in this chapter, look into the way each operator works.
Decision making structures require that the programmer specifies one or more conditions
to be evaluated or tested by the program, along with a statement or statements to be
executed if the condition is determined to be true, and optionally, other statements to be
executed if the condition is determined to be false.
Show below is the general form of a typical decision making structure found in most of
the programming languages −
C programming language assumes any non-zero and non-null values as true, and if it is
either zero or null, then it is assumed as false value.
3.5 C Loops
Programming languages provide various control structures that allow for more
complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times.
1 while loop :
Repeats a statement or group of statements while a given condition is true. It tests the
condition before executing the loop body.
2 for loop :
Executes a sequence of statements multiple times and abbreviates the code that
manages the loop variable.
3 do...while loop :
It is more like a while statement, except that it tests the condition at the end of the loop
body.
4 nested loops :
You can use one or more loops inside any other while, for, or do..while loop.
3.6 C Functions
A function is a group of statements that together perform a task. Every C program has at
least one function, which is main(), and all the most trivial programs can define
additional functions.
A function definition in C programming consists of a function header and a function
body. Here are all the parts of a function −
1. Return Type − A function may return a value. The return_type is the data type of
the value the function returns. Some functions perform the desired operations
without returning a value. In this case, the return_type is the keyword void.
2. Function Name − This is the actual name of the function. The function name and
the parameter list together constitute the function signature.
3. Parameters − A parameter is like a placeholder. When a function is invoked, you
pass a value to the parameter. This value is referred to as actual parameter or
argument. The parameter list refers to the type, order, and number of the
parameters of a function. Parameters are optional; that is, a function may contain
no parameters.
4. Function Body − The function body contains a collection of statements that define
what the function does.
3.7 Array
Arrays a kind of data structure that can store a fixed-size sequential collection of
elements of the same type . An array is used to store a collection of data, but it is often
more useful to think of an array as a collection of variables of the same type.
Instead of declaring individual variables, such as number0, number1, ..., and number99,
you declare one array variable such as numbers and use numbers[0], numbers[1], and ...,
numbers[99] to represent individual variables. A specific element in an array is accessed
by an index.
All arrays consist of contiguous memory locations. The lowest address corresponds to the
first element and the highest address to the last element.
1 Multi-dimensional arrays
C supports multidimensional arrays. The simplest form of the multidimensional array is the two-
dimensional array.
4 Pointer to an array
You can generate a pointer to the first element of an array by simply specifying the array name,
without any index.
3.8 C Pointers
Pointers in C are easy and fun to learn. Some C programming tasks are performed more
easily with pointers, and other tasks, such as dynamic memory allocation, cannot be
performed without using pointers. So it becomes necessary to learn pointers to become a
perfect C programmer. Let's start learning them in simple and easy steps.
As you know, every variable is a memory location and every memory location has its
address defined which can be accessed using ampersand (&) operator, which denotes an
address in memory.
1 Pointer arithmetic
There are four arithmetic operators that can be used in pointers: ++, --, +, -
2 Array of pointers
You can define arrays to hold a number of pointers.
3 Pointer to pointer
C allows you to have pointer on a pointer and so on.
3.9 C String
▪ Strlen()
▪ Strcpy()
▪ Strcat()
▪ Strcmp()
▪ Strrev()
▪ Strchr()
3.10 C Structure
Arrays allow to define type of variables that can hold several data items of the same kind.
Similarly structure is another user defined data type available in C that allows to
combine data items of different kinds.
Structures are used to represent a record. Suppose you want to keep track of your books
in a library. You might want to track the following attributes about each book –
member definition;
member definition;
...
member definition;
}
3.11 C Union
A union is a special data type available in C that allows to store different data types in
the same memory location. You can define a union with many members, but only one
member can contain a value at any given time. Unions provide an efficient way of using
the same memory location for multiple-purpose.
To define a union, you must use the union statement in the same way as you did while
defining a structure. The union statement defines a new data type with more than one
member for your program.
member definition;
member definition;
...
member definition;
}
The union tag is optional and each member definition is a normal variable definition,
such as int i; or float f; or any other valid variable definition. At the end of the union's
definition, before the final semicolon, you can specify one or more union variables but it
is optional.
A file represents a sequence of bytes, regardless of it being a text file or a binary file. C
programming language provides access on high level functions as well as low level (OS
level) calls to handle file on your storage devices.
Filename is a string literal, which you will use to name your file, and access mode can
have one of the following values –
1
R
Opens an existing text file for reading purpose.
2
W
Opens a text file for writing. If it does not exist, then a new file is created. Here your
program will start writing content from the beginning of the file.
3
A
Opens a text file for writing in appending mode. If it does not exist, then a new file is
created. Here your program will start appending content in the existing file content.
4
r+
Opens a text file for both reading and writing.
5
w+
Opens a text file for both reading and writing. It first truncates the file to zero length if it
exists, otherwise creates a file if it does not exist.
6
a+
Opens a text file for both reading and writing. It creates the file if it does not exist. The
reading will start from the beginning but writing can only be appended.
CHAPTER-4
DATA TYPES
Data types in c refer to an extensive system used for declaring variables or functions of
different types. The type of a variable determines how much space it occupies in storage
and how the bit pattern stored is interpreted.
4.1 Data Types In C
1 Basic Types
They are arithmetic types and are further classified into: (a) integer types
and (b) floating-point types.
2 Enumerated types
They are again arithmetic types and they are used to define variables that
can only assign certain discrete integer values throughout the program.
4 Derived types
They include (a) Pointer types, (b) Array types, (c) Structure types, (d)
Union types and (e) Function types.
The following table provide the details of standard floating-point types with storage sizes
and value ranges and their precision –
The void type specifies that no value is available. It is used in three kinds of situations –
3 Pointers to void
A pointer of type void * represents the address of an object, but not its type. For example,
a memory allocation function void *malloc( size_t size ); returns a pointer to void which
can be casted to any data type.
4.5 C Variables
A variable is nothing but a name given to a storage area that our programs can
manipulate. Each variable in C has a specific type, which determines the size and layout
of the variable's memory; the range of values that can be stored within that memory; and
the set of operations that can be applied to the variable.
1 char
Typically a single octet(one byte). It is an integer type.
2 int
The most natural size of integer for the machine.
3 float
A single-precision floating point value.
4 double
A double-precision floating point value.
5 void
Represents the absence of type.
A variable declaration provides assurance to the compiler that there exists a variable with
the given type and name so that the compiler can proceed for further compilation without
requiring the complete detail about the variable. A variable definition has its meaning at
the time of compilation only, the compiler needs actual variable definition at the time of
linking the program.
A variable declaration is useful when you are using multiple files and you define your
variable in one of the files which will be available at the time of linking of the program.
You will use the keyword extern to declare a variable at any place. Though you can
declare a variable multiple times in your C program, it can be defined only once in a file,
a function, or a block of code.
A variable definition tells the compiler where and how much storage to create for the
variable.
CHAPTER-5
CONCLUSION
We are at the end of this book. You have probably read everything and also tested
some pieces of code with your own hardware, and I'm sure you are now able to
imagine your future and advanced projects with Arduino.
I wanted to thank you for being so focused and interested. I know you are now
almost in the same boat as myself, you want to learn more, test more, and check
and use new technologies in order to achieve your craziest project. I'd like to say
one last thing: do it, and do it now!
In most cases, people are afraid of the huge amount of work that they can imagine
in the first steps just before they start. But you have to trust me, don't think too
much about details or about optimization. Try to make something simple,
something that works. Then you'll have ways to optimize and improve it.
REFERENCES
Web References
● https://www.geeksforgeeks.org/c-programming-language/?ref=leftbar
● https://github.com/topics/c-language
● https://www.programiz.com/c-programming
● https://www.tutorialspoint.com/cprogramming/index.htm
● https://www.programiz.com/c-programming/examples