CSC203 Slide
CSC203 Slide
CSC203 Slide
CSC 203
2
Features of C language
3
C character set
4
C character set…contd
2. Execution character set : This set of characters
are invisible and cannot be printed or displayed
directly. They will have effect only when the program is
being executed. These characters are represented by
a back slash (\) followed by a character.
5
Structure of a C program
6
Structure of a C program
8
Basic data types in C
1. Character data: Any character of the ASCII
character set can be considered as a character
data types and its maximum size can be 1 byte or
8 byte long. ‘Char’is the keyword used to represent
character data type in C.
2. Integer data: The keyword ‘int’ stands for the
integer data type in C and its size is either 16 or 32
bits.
3. Floating point data:- The numbers which are
stored in floating point representation with
mantissa and exponent are called floating point
(real) numbers.
4. Double data : - Double is a keyword in C to
represent double precision floating point numbers. 9
Delimiters in C
10
Variables / Identifiers
11
Operators
An Operator is a symbol that operates on a certain data
type. The data items that operators act upon are called
operands. Some operators require two operands,
some operators act upon only one operand. Operators
in C program includes;
1. Arithmetic Operators
2. Relational Operators
3. Logical Operator
4. Assignment Operator
5. Increment & Decrement Operator
6. Conditional Operator
12
Arithmetic operators
Arithmetic operators performs arithmetic operations.
The Arithmetic operators can operate on any built in
data type. A list of arithmetic operators and their
meaning are;
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo division
13
Relational operators
Relational Operators are used to compare arithmetic,
logical and character expressions. The Relational
Operators compare their left hand side expression with
their right hand side expression. Then evaluates to an
integer. If the Expression is false it evaluate to “zero”(0)
if the expression is true it evaluate to “one” (1)
Operator Meaning
< Less than
> Greater than
<= Less than or Equal to
>= Greater than or Equal to
== Equal to
14
!= Not Equal to
Logical operators
A logical operator is used to evaluate logical and
relational expressions. The logical operators act upon
operands that are themselves logical expressions.
There are three logical operators.
Operators Expression
&& Logical AND
|| Logical OR
! Logical NOT
15
Assignment operators
• An assignment operator is used to assign a value to
a variable. The most commonly used assignment
operator is =. The general format for assignment
operator is :
<Identifer> = < expression >
16
Increment/Decrement operators
The increment/decrement operator act upon a Single
operand and produce a new value is also called as
“unary operator”. The increment operator ++ adds 1 to
the operand and the Decrement operator - - subtracts 1
from the operand.
Syntax: < operator >< variable name >;
17
Conditional operators
It is called ternary because it uses three expression.
The ternary operator acts like If- Else construction.
Syn :( <Exp –1 > ? <Exp-2> : <Exp-3> );
18
Expressions and its evaluation procedure
An expression can be defined as collection of data object and operators
that can be evaluated to lead a single new data object. A data object is a
constant, variable or another data object.
• Evaluation Procedure: The evaluation of arithmetic expressions is
as per the hierarchy rules governed by the C compiler. The
precedence or hierarchy rules for arithmetic expressions are
• 1. The expression is scanned from left to right.
• 2. While scanning the expression, the evaluation preference for the
operators are
*, /, % - evaluated first
+, - - evaluated next
• 3. To overcome the above precedence rules, user has to make use of
parenthesis. If parenthesis is used, the expression/ expressions with
in parenthesis are evaluated first as per the above hierarchy.
19
Statements
• Data Input & Output
An input/output function can be accessed from
anywhere within a program simply by writing the
function name followed by a list of arguments enclosed
in parentheses. The arguments represent data items
that are sent to the function.
20
Statements…contd
1. getchar()
• Single characters can be entered into the computer
using the C library Function getchar(). It returns a
single character from a standard input device. The
function does not require any arguments.
• Syntax: <Character variable> = getchar();
• Example: char c;
c = getchar();
21
Statements…contd
2. putchar()
• Single characters can be displayed using function
putchar(). It returns a single character to a standard
output device. It must be expressed as an argument
to the function.
• Syntax: putchar(<character variable>);
• Example: char c;
putchar(c);
22
Statements…contd
3. scanf()
• Scanf() function can be used input the data into the
memory from the standard input device. This function
can be used to enter any combination of numerical
Values, single characters and strings. The function
returns number of data items.
• Syntax: -scanf (“control strings”, &arg1,&arg2, &argn);
Where control string reference to a string containing
certain required formatting information and arg1,
arg2,…argn are arguments that represent the individual
input data items.
23
Statements…contd
24
Statements…contd
4. printf()
• The printf() function is used to print the data from the
computer’s memory onto a standard output device.
This function can be used to output any combination
of numerical values, single character and strings.
• Syntax: printf(“control string”, arg-1, arg-2,… arg-n );
Where control string is a string that contains
formatted information, and arg-1, arg-2… are
arguments that represent the output data items.
25
Statements…contd
• Assignment statement
Assignment statement can be defined as the statement
through which the value obtained from an expression
can be stored in a variable.
The general form of assignment statement is
< variable name> = < arithmetic expression> ;
26