ES202-Introduction To Computers and Programming in C: Amity School of Engineering and Technology
ES202-Introduction To Computers and Programming in C: Amity School of Engineering and Technology
Lab-1
ES202-Introduction to Computers and
Programming in C
Introduction to C
• 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.
2
Introduction to C
• The Unix operating system and virtually all
Unix applications are written in the C
language. C has now become a widely
used professional language for various
reasons.
• Easy to learn
• Structured language.
• It can handle low-level activities.
• It can be compiled on a variety of
computers.
3
Facts about C
• C is a successor of B language which was
introduced around 1970
• The language was formalized in 1988 by
the American National Standard Institue
(ANSI).
• By 1973 UNIX OS almost totally written in
C.
• Today C is the most widely used System
Programming Language.
4
Why to use C
• C was initially used for system
development work, in particular the
programs that make-up the operating
system. Some examples of the use of C
might be:
• Operating Systems
• Language Compilers
• Assemblers
• Text Editors
• Print Spoolers
• Network Drivers
• Data Bases
• Language Interpreters
5
C-Program Structure
6
Important Points
• C is a case sensitive programming
language. In C printf and Printf will have
different meanings.
• End of each C statement must be marked
with a semicolon.
• Multiple statements can be one the same
line.
7
Important Points
• White Spaces (ie tab space and space bar
) are ignored.
• Statements can continue over multiple
lines
• Comments: are used to give additional
useful information inside a C Program. All
the comments will be put inside /*...*/
(Multi-line Comment) or //(End-of-line
Comment)
8
Preprocessor directive
#include <stdio.h>
The "#include" is called a preprocessor
directive. A preprocessor directive begins
with a # sign, and is processed before
compilation. The directive "#include
<stdio.h>" tells the preprocessor to include
the "stdio.h" header file to support
input/output operations.
9
int main() { ...... }
• The main() function is the entry point of
program execution. main() is required to
return an int (integer).
10
C Program Template
/* * Comment to state the purpose of this
program (filename.c) */
#include <stdio.h>
int main()
{
// Your Programming statements HERE!
return 0;
}
11
Program
• A program is a sequence of
instructions (called programming
statements), executing one after another
usually in a sequential manner
12
Online C Compiler
https://
www.onlinegdb.com/online_c_compiler
13
First Sample Program
/* First C program (Hello.c) */
• #include <stdio.h> // Needed to perform
IO operations
int main() { // Program entry point
printf("Hello, world!\n"); // Says Hello
return 0; // Terminate main()
} // End of main()
14
printf("Hello, world!\n");
• Invoke the function printf() to print the
string "Hello, world!" followed by a newline
(\n) to the console.
• The newline (\n) brings the cursor to the
beginning of the next line.
15
Return statement
• return 0;
terminates the main() function and returns a
value of 0 to the operating system. Typically,
return value of 0 signals normal termination;
whereas value of non-zero (usually 1)
signals abnormal termination. This line is
optional. C compiler will implicitly insert a
"return 0;" to the end of the main() function.
16
Case Sensitive
• C is a case sensitive Language.
17
Variable
• Computerprograms manipulate (or proces
s) data.
• A variable is used to store a piece of data
for processing. It is called variable.
• a variable is a named storage location,
that stores a value of a particular
data type. In other words, a variable has
a name, a type and stores a value of that
type.
18
Data Types
19
Basic Data Types
Int (Integer)
Store integer type of data.
• 2 bytes (16 bits) on a 16-bit machine.
• The modern systems have 32 or 64-bit
configurations. The size of an integer in
such environment is 4 bytes with
a starting value of -2,147,483,648 and
an ending value as 2,147,483,647.
20
Basic Data Types
Float
• This datatype is also numeric but allows
numbers with decimal places. It has a size
of 4 bytes and has a range of 3.4E-38 to
3.4E+38.
• The float type has a precision up to 7
digits.
21
Basic Data Type
Double
• It is same as float but with a higher
precision range that is 8 bytes which gives
it an ability to store more numerals after
the decimal places, double to be exact.
• It has a length of 8 bytes and has a range
of 1.7E +/- 308. The double data type has
a precision up to 15 digits.
22
Basic Data Types
Char
Char data type by default allows a single
character such as a letter from the alphabet.
It has the size of just 1 byte with a range of -
128 to 127 or 0 to 255.
23
Program
• WAP to find area of circle
• WAP to divide two numbers
• WAP to add two integers
• WAP to print ASCII value
• WAP to multiply floating point numbers
24
25