Day_1 C-Programming
Day_1 C-Programming
Topics
ALGORITHM
● Algorithm refers to the logic of the program. It is a step by step description of how to
arrive at the solution of the problem.
● An algorithm is a complete, detailed and precise step by step method for solving a
problem independently of the hardware and software.
1. Begin
2. Input the value of A and B
3. SUM= A+B
4. Display SUM
5. End.
FLOWCHART
● A flowchart is a pictorial representation of an algorithm or process.
Symbols used:
COMPUTER LANGUAGES
LANGUAGE TRANSLATORS
○ Assembler
○ Interpreter
○ Compiler
Assembler
● This language processor converts the program written in assembly language into
machine language.
Interpreter
Compiler
Applications of C programming
Applications of C programming is a powerful and versatile language used in various domains
due to its efficiency, performance, and flexibility. Here are some key applications of C
programming:
Identify Inputs and Outputs: Specify what data you will receive as input and what data
you need to output.
Outline Steps: Break down the problem into a series of logical steps. Use pseudocode
or flowcharts to represent these steps.
Consider Edge Cases: Think about possible edge cases and how your algorithm will
handle them.
Iterate and Refine: Review and refine your algorithm to ensure it covers all aspects of
the problem.
Syntax errors
● Syntax errors occur when the rules of the C language are violated. These are detected
by the compiler during the compilation process.
● Common Causes:
○ Misspelled keywords
○ Missing semicolons at the end of statements
○ Mismatched parentheses, brackets, or braces
○ Incorrect use of operators
Logical errors
● Logical errors occur when the program compiles and runs, but the output is not as
expected. These are errors in the logic or algorithm used in the program.
● Common Causes:
○ Incorrect algorithm implementation
○ Wrong conditions in loops or if statements
○ Incorrect use of variables or operators
Runtime Errors
● Runtime errors occur while the program is running. These errors are not detected during
compilation and typically cause the program to terminate abnormally.
● Common Causes:
○ Division by zero
○ Null pointer dereferencing
○ Array index out of bounds
○ Memory allocation failures
C programming:
Example 1: use semicolon ; at the end of every statement.
Example 2: variable declaration is important before using them. Use %d for int and %f for float.
Features of C
1. Procedural Language
2. Fast and Efficient
3. Modularity
4. General-Purpose Language
5. Rich set of built-in Operators
6. Libraries with Rich Functions
7. Middle-Level Language: C is High level language with some features of low level
language, hence, it is called middle level language.
8. Portability: Programs that are written in C language can run and compile on any system
with either no or small changes.
9. Easy to Extend
C Tokens
Keywords
Keywords are predefined or reserved words that have special meanings to the compiler. These
are part of the syntax and cannot be used as identifiers in the program. A list of keywords in C
or reserved words in the C programming language are mentioned below:
Identifier
Identifier is a name used to identify a variable, function, or array.
Rules for constructing C identifiers
1. Identifiers must start with a letter or an underscore.
2. Identifiers can only contain letters, digits, and underscores.
3. No Commas or blank spaces within an identifier.
4. Identifiers are case-sensitive.
5. Identifiers cannot be a reserved keyword.
6. The length of the identifiers should not be more than 31 characters.
C-Constants
Operators
C language provides a wide range of operators that can be classified into 6 types based on their
functionality:
1. Arithmetic Operators
2. Assignment Operators
3. Increment Decrement Operators
4. Relational Operators
5. Logical Operators
6. Bitwise Operators
7. Conditional Operator
8. Special Operator
1. Arithmetic Operators:
2. Assignment Operators
3. Increment Decrement Operators
4. Relational operators
5. Logical Operators
6. Bitwise Operators
7. Conditional Operator
Also called ternary operator as it takes 3 operands.
exp1 ? exp2 : exp3
Example:
8. Special Operators
These will be discussed later when we will be using them in upcoming chapters.
A. , comma operator
B. . member access operator
C. sizeof() operator
D. * dereferencing operator
Example2: (associativity)
3 - 4 + 6 (Here + and - both have the same precedence so according to associativity of
arithmetic operators, which is left to right, in this example - will be evaluated before +)
Example3: (associativity)
3 + 4 - 6 (Here + and - both have the same precedence so according to associativity of
arithmetic operators, which is left to right, in this example + will be evaluated before -)
Data Types
-2,147,483,648 to
int 4 %d
2,147,483,647
-2,147,483,648 to
long int 4 %ld
2,147,483,647
1.7E-308 to
double 8 %lf
1.7E+308
3.4E-4932 to
long double 16 %Lf
1.1E+4932
Type Conversion in C