Unit I C
Unit I C
BASICS OF C PROGRAMMING
English
Tamil
Lowercase a to z a, b, c, d, e, f, g, h, i, j, k, l, m, n,
Alphabets o, p, q, r, s, t, u, v, w, x, y, z
Uppercase A to Z A, B, C, D, E, F, G, H, I, J, K, L, M,
Alphabets N, O, P, Q, R, S, T, U, V, W, X, Y, Z
Digits 0 to 9 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special – `~@!$#^*%&()[]{}<>+
Characters =_–|/\;:‘“,.?
• Later when we are storing an element into a location that is identified by the
identifier “a” as follows.
• a = 10; //Here, the value is 10 and we are setting this value into a memory
location which is identified by “a” as shown in the below image.
Will be
discussed in
detail now
•signed data type can store both positive or negative values (default)
•unsigned type strictly accepts only positive values (Negative values will not be
accepted)
9/20/2023
Computer Centre - Madras Institute of
41
Technology
Basic/Primitive data types Cont’d
Size and Range of Data Types in C Language
• The size of data types in C depends on the implementation and the system architecture.
• However, the following table provides the standard minimum and maximum sizes and range
of each data type as defined by the C standard:
While ++m and m++ mean the same thing when they form statements
independently
They behave differently when they are used in expressions on the right-hand
side of an assignment statement
m=5;
y=++m;
The value of y and m would be 6
m=5;
y=m++;
The value of y would be 5 and m would be 6
A prefix operator first adds 1 to the operand and then the result is assigned to
the variable on left
A postfix operator first assigns the value to the variable on left and then
increments the operand
Computer Centre - Madras Institute of
9/20/2023 59
Technology
Operators – Cont’d
(Relational Operators)
• These Operators are used to check the relationship between the two
operands.
– If the relation is true, it returns 1
– if the relation is false, it returns the value 0.
• Relational operators are used in decision-making and loops.
Output:
+= plus assign a += b a= a + b
*= times assign a *= b a = a* b
/= div assign a /= b a =a / b
%= Mod assign a %= b a= a % b
Computer Centre - Madras Institute of
9/20/2023 64
Technology
Operators – Cont’d
(Assignment Operators - Example)
Output:
(105)10 = (1101001)2
(78)10=(100 1110)2
a= 32 = 0010 0000
a>>1 = 0001 0000 =16
a>>2 = 0000 1000 = 8
Output:
Output:
Output:
• Symbolic Constants:
#define instruction defines value of a symbolic constant
Symbolic constant values remain constant throughout the execution of
the program
#define is a compiler directive and not a statement
#define line should not end with a semicolon
#define instructions are placed at the beginning before main() function
Symbolic constants are written in uppercase
Symbolic constants are not declared in declaration section
Computer Centre - Madras Institute of
9/20/2023 95
Technology
Input and Output Statements
• Input means to feed some data INTO a program
• Output means to display data on the screen or write the data
to a printer or a file.
• C language offers us several built-in functions for performing
input/output operations
•The gets() is used to read string from standard input file stdin
Computer Centre - Madras Institute of
9/20/2023 99
Technology
Input and Output Statements Cont’d
Unformatted I/O Functions –Cont’d
• While calling any of the unformatted console output
functions, we do not have to use any format specifiers in
them, to display a value on the console.
• Hence, these functions are named as unformatted console
output functions.
• The opening and closing braces should be balanced, for example, if opening
braces are four, then closing braces should also be four
Computer Centre - Madras Institute of
9/20/2023 106
Technology
Translators and their needs in
Programming Languages
• User’s give instructions in C program code (high level
language) which is also called as source code.
• But the computer ‘s wont understand the source code
• Computer’s only understandable code is binary / machine.
• To convert this source code into binary code we are using the
interface software called translators.
• Translators are system software that converts programming
language code into binary format.
• The translators are classified into three types:
– Compiler
– Interpreter
– Assembler
Sequential control is an implicit form of control in which instructions are executed
in the order that they are written. A program consisting of only sequential control is
referred to as a “straight-line program.”
Selection control is provided by a control statement that selectively executes instructions
Iterative control is provided by an iterative control statement that repeatedly
executes instructions
Computer Centre - Madras Institute of
9/20/2023 114
Technology
Control Statements –Cont’d
UNIT 1 UNIT 2
if-else Statement
•The if-else statement is used for testing Syntax:
condition. If the condition is true, if block if(condition)
executes otherwise else block executes. {
//code for true
•It is useful in the scenario when we want to
}
perform some operation based on the false else
result. {
•The else block execute only when condition is //code for false
false. }
Computer Centre - Madras Institute of
9/20/2023 117
Technology
If Example
Output 1:
Output 2:
Output 1:
Output 2:
Output 1:
Output 2:
Output 3:
Output 1:
Output 2:
Output 3:
default:
code for execution when none of the case is true;
} 9/20/2023
Computer Centre - Madras Institute of
125
Technology
//Program to check whether the entered character is vowel or not
Output 1:
Output 2:
Output 3:
Output 1:
Output 2:
Output 3: