1st Unit
1st Unit
1
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
Step 1. INPUT TO A, B
Step 4. STOP
2
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• In a flowchart, boxes of different shapes are used to denote different types of operations.
These boxes are then connected by lines with arrows denoting the flow or direction to which
one should proceed to know the next step.
3
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
Example of flowchart
# include<stdio.h>
Int main ()
{
int a , b , c ;
a = 5;
b = 7;
c = a + b;
printf(“%d”, c )
return 0;
5
}
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• It is now one of the most popular and influential programming languages worldwide.
6
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• History C
• Importance of C :
8
Compatibility • C code can be easily integrated with code written in other
languages like C++, Java, and Python
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• Character Set :
9
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
Tokens in C :
10
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• Keywords :
volatile while
01/20/2025
• // Example of the if-keyword token in C
• #include <stdio.h>
•
12
01/20/2025
• / Example of identifier tokens in C
14
• Types Of Operator Tokens In C
01/20/2025
• The operator tokens in C can be classified into two types- unary operators and binary operators, depending on
the number of operands they take.
1.Unary Operator Tokesn In C
• A unary operator is an operator that operates on a single operand or variable in an expression. It performs an
operation or transformation on the value of the operand and typically returns a new value. The unary operator
• Identifiers :
4 Examples of keywords are double, int, Examples of IDs are test, count1, high speed,
18
auto, char, break, and many others. etc.
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• Constants :
Integer
Real
Primary
Character
Constants
Array
Pointer
Secondary
Structure
19
Union
Enum , etc
C constants
• C Constants is a most fundamental and essential part of C programming language.
Constants in C are the fixed values that are used in a program, and its value remains
the same during the entire execution of the program.
• Constants are also called literals.
• Constants can be any of the data types.
• A constant is a value or variable that can't be changed in the program, for example:
10, 20, 'a', 3.4, "c programming" etc.
C constants
• Constants can be of any of the basic data types like an integer constant, a floating
constant, a character constant, or a string literal. There are enumeration constants
as well.
• Syntax
• const type constant_name;
• const keyword defines a constant in C.
Fundamentals of Programming languages 01/20/2025
22
Example of constant
• #include<stdio.h>
• int main()
• {
• const float PI=3.14;
• printf("The value of PI is: %f",PI);
• return 0;
• }
Cont…
• If you try to change the value of PI, it will render compile time error.
• #include<stdio.h>
• int main(){
• const float PI=3.14;
• PI=4.5;
• printf("The value of PI is: %f",PI);
• return 0;
• }
Integer constant
• It's referring to a sequence of digits. Integers are of three types:
• Decimal Integer
• Octal Integer
• Hexadecimal Integer
• Example:
• 15, -265, 0, 99818, +25, 045, 0X6
• Real constant
Real constant
• The numbers containing fractional parts like 99.25 are called real or floating points constant.
• Example:
• 'X', '5', ';'
String constant
• These are a sequence of characters enclosed in double quotes, and they may include
letters, digits, special characters, and blank spaces. It is again to be noted that "G"
and 'G' are different - because "G" represents a string as it is enclosed within a pair of
double quotes whereas 'G' represents a single character.
• Example:
• "Hello!", "2015", "2+1"
Backslash character constant
• C supports some character constants having a backslash in front of it. The lists of
backslash characters have a specific meaning which is known to the compiler. They
are also termed as "Escape Sequence".
• For Example:
• \t is used to give a tab
• \n is used to give a new line
• // C program to illustrate constant variable definition
01/20/2025
• #include <stdio.h>
• int main()
• { // defining integer constant using const keyword
30
01/20/2025
• Advantages of Using Constants in C
• Using constants in C has several advantages over using variables. Some of the
advantages are:
• Variables :
C Variable Syntax
Data type variable name = value;
or
data type variable_name1, variable_name2;
Example
Int var; // integer variable
char a; // character variable
float fff; // float variables
32
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• Data types :
33
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• Declaration of variables:
• E xample:
34
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• Storage Classes in C
• These features basically include the scope, visibility, and lifetime which help us to trace the existence
of a particular variable during the runtime of a program.
35
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
36
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• Here:
• “ int ” is the data type.
• “ a ” is the variable.
• “ = " is the operator.
• “ 4 ” is the value.
37
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
38
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
• example:
const int MAX_VALUE = 100;
This will create a constant variable named MAX_VALUE with a value of 100.
39
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
4 40
Constants have fixed face Variables do not have a fixed face
values. value..
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
41
01/20/2025
UNIT –I Introduction to Program Planning & C Programming
01/20/2025
• Escape sequence is a character followed by a blackslash(\)
• They are used especially to perform some special operations like going to new
line,providing a horizontal tab,vertical tab etc….
44
01/20/2025
• Example to demonstrate how to use \b escape sequence in C
46
1. Syntax Errors
01/20/2025
• These are also referred to as compile-time errors. These errors have occurred when the rule of C
writing techniques or syntaxes has been broken. These types of errors are typically flagged by the
compiler prior to compilation.
• / C program to demonstrate
• // a syntax error due to
• // missing semi colon
• #include <stdio.h>
•
• // Driver code
• int main()
• {
• // missing semicolon
47
• printf("Geeks for geeks!")
• return 0;
• }
Fundamentals of Programming languages 01/20/2025
48
Semantic Errors
01/20/2025
• When a sentence is syntactically correct but has no meaning, semantic errors occur.
This is similar to grammatical errors. If an expression is entered on the left side of the
assignment operator, a semantic error may occur.
01/20/2025
• Enumeration (or enum) is a user defined data type in C. It is mainly used to assign
names to integral constants, the names make a program easy to read and maintain.
int main()
{
enum week day;
day = Wed;
printf("%d",day);
return 0;
}
Output:
53
2
01/20/2025
/ Another example program to demonstrate working
// of enum in C
#include<stdio.h>
int main()
{
int i;
for (i=Jan; i<=Dec; i++)
printf("%d ", i);
return 0;
}
Output:
0 1 2 3 4 5 6 7 8 9 10 11 54
01/20/2025
Integrated Development Environment(IDE):
55
01/20/2025
This IDE Contains 5
Tools:Editor,Preprocessor,Compiler,Linker and Loader
57
Fundamentals of Programming languages 01/20/2025
58