0% found this document useful (0 votes)
5 views15 pages

Computer Programming

The document contains exam preparation notes for Computer Programming (EE203ESC05), covering key topics such as C programming basics, control structures, arrays, functions, pointers, and file handling. It includes content from uploaded PPTs, unit notes, previous year papers, and mid-semester papers, with a target score of 40+/60. The notes are structured into units with detailed explanations and examples for each topic.

Uploaded by

ladaayush92
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views15 pages

Computer Programming

The document contains exam preparation notes for Computer Programming (EE203ESC05), covering key topics such as C programming basics, control structures, arrays, functions, pointers, and file handling. It includes content from uploaded PPTs, unit notes, previous year papers, and mid-semester papers, with a target score of 40+/60. The notes are structured into units with detailed explanations and examples for each topic.

Uploaded by

ladaayush92
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Programming

EE203ESC05

Exam Preparation Notes

Prepared According to:

• Uploaded PPTs

• Unit Notes

• Previous Year Papers

• Latest Mid Semester Papers

Target Score: 40+/60


Academic Study Notes
EE203ESC05 Computer Programming

Contents

1 UNIT 1 : Basics of C Programming 3


1.1 Procedure Oriented Programming (POP) . . . . . . . . . . . . . . . . . . 3
1.2 Introduction to C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Compiler vs Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Tokens in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.6 Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.7 Variables and Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.8 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.9 Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2 UNIT 2 : Control Structures 5


2.1 if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 if-else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Else-if Ladder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Nested if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 Ternary Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.7 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.8 Difference Between while and do-while . . . . . . . . . . . . . . . . . . . 7
2.9 Jump Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3 UNIT 3 : Arrays and Strings 8


3.1 Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Diagram of Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Program to Read and Print Array . . . . . . . . . . . . . . . . . . . . . . 8
3.4 Sum of Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.5 Average of Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.6 2D Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.7 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4 UNIT 4 : Functions 10
4.1 Concept of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 Syntax of Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3 Function Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.4 void Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.5 Library Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.6 String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5 UNIT 5 : Pointers 11
5.1 Introduction to Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.2 Pointer Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.3 Pointer Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.4 Call by Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.5 Call by Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

1
EE203ESC05 Computer Programming

6 UNIT 6 : Structures and File Handling 12


6.1 Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6.2 Declaring Structure Variable . . . . . . . . . . . . . . . . . . . . . . . . . 12
6.3 Accessing Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6.4 Array of Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6.5 File Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

7 Most Important Programs for Exam 13

8 Exam Strategy for 40+/60 13

9 Conclusion 14

2
EE203ESC05 Computer Programming

1. UNIT 1 : Basics of C Programming


1.1. Procedure Oriented Programming (POP)
Definition:
Procedure Oriented Programming is a programming approach where the complete
program is divided into small functions or procedures.

Why It Matters
• Makes program modular

• Reusability of code

• Easier debugging

Advantages
• Simple to understand

• Functions can be reused

• Suitable for small programs

Disadvantages
• Low security

• Difficult for large projects

• Not suitable for real-world modeling

1.2. Introduction to C
C is a general-purpose programming language developed by Dennis Ritchie in 1972 at
AT&T Bell Labs.

Features of C
• Portable

• Fast execution

• Structured programming

• Rich library functions

• Pointer support

3
EE203ESC05 Computer Programming

1.3. Compiler vs Interpreter

Compiler Interpreter
Converts whole program Converts line by line
Execution faster Execution slower
Errors shown after compilation Errors shown immediately

1.4. Tokens in C
A token is the smallest meaningful unit in C.

Types of Tokens
1. Keywords

2. Identifiers

3. Constants

4. Strings

5. Operators

6. Special Symbols

1.5. Keywords
Keywords are reserved words having predefined meaning.
Examples:
1 int
2 float
3 return
4 if
5 else

1.6. Identifiers
Identifiers are names given to variables, functions, arrays etc.

Rules
• Cannot start with number

• No spaces allowed

• Case sensitive

• Keywords cannot be used

4
EE203ESC05 Computer Programming

1.7. Variables and Constants


Variable:
1 int age = 20;

Constant:
1 const int x = 10;

1.8. Data Types


Datatype Size Format Specifier
int 2 bytes %d
char 1 byte %c
float 4 bytes %f
double 8 bytes %lf

1.9. Type Conversion


Implicit Conversion
Automatically performed by compiler.
1 int a = 5;
2 float b = a ;

Explicit Conversion
Manually performed by programmer.
1 float x = 5.6;
2 int y = ( int ) x ;

2. UNIT 2 : Control Structures


2.1. if Statement
Used to execute statements only when condition is true.

Syntax
1 if ( condition )
2 {
3 statements ;
4 }

5
EE203ESC05 Computer Programming

Example
1 if (a > b )
2 {
3 printf ( " A ␣ is ␣ greater " ) ;
4 }

2.2. if-else Statement


Used for two-way decision making.
1 if ( num %2==0)
2 printf ( " Even " ) ;
3 else
4 printf ( " Odd " ) ;

2.3. Else-if Ladder


Used when multiple conditions are present.
1 if ( marks >=75)
2 printf ( " Distinction " ) ;
3 else if ( marks >=60)
4 printf ( " First ␣ Class " ) ;
5 else
6 printf ( " Fail " ) ;

2.4. Nested if
if statement inside another if statement.
1 if (a >0)
2 {
3 if ( a %2==0)
4 printf ( " Positive ␣ Even " ) ;
5 }

2.5. Switch Statement


Alternative to else-if ladder.

Syntax
1 switch ( expression )
2 {
3 case 1:
4 statements ;
5 break ;
6

6
EE203ESC05 Computer Programming

7 default :
8 statements ;
9 }

2.6. Ternary Operator


Short form of if-else.
1 max = (a > b ) ? a : b ;

2.7. Loops
for Loop
Best when number of iterations is known.
1 for ( i =0; i <5; i ++)
2 {
3 printf ( " % d " ,i ) ;
4 }

while Loop
Entry controlled loop.
1 while ( condition )
2 {
3 statements ;
4 }

do-while Loop
Exit controlled loop.
1 do
2 {
3 statements ;
4 } while ( condition ) ;

2.8. Difference Between while and do-while


while do-while
Entry controlled Exit controlled
May execute zero times Executes at least once
Condition checked first Condition checked last

7
EE203ESC05 Computer Programming

2.9. Jump Statements


• break

• continue

• goto

• return

3. UNIT 3 : Arrays and Strings


3.1. Array
An array is a collection of elements of same datatype stored in contiguous memory loca-
tions.

Declaration
1 int marks [5];

Initialization
1 int marks [5]={10 ,20 ,30 ,40 ,50};

Accessing Elements
1 marks [0]
2 marks [1]

3.2. Diagram of Array

2 4 8 12 16

0 1 2 3 4

3.3. Program to Read and Print Array


1 # include < stdio .h >
2

3 int main ()
4 {
5 int arr [5];
6

7 for ( int i =0; i <5; i ++)

8
EE203ESC05 Computer Programming

8 {
9 scanf ( " % d " ,& arr [ i ]) ;
10 }
11

12 for ( int i =0; i <5; i ++)


13 {
14 printf ( " % d ␣ " , arr [ i ]) ;
15 }
16

17 return 0;
18 }

3.4. Sum of Array


1 sum = sum + arr [ i ];

3.5. Average of Array


1 avg = sum / n ;

3.6. 2D Array
Declaration
1 int a [3][3];

Accessing
1 a [ i ][ j ]

3.7. Strings
Declaration
1 char name [20];

Initialization
1 char name [] = " Hello " ;

Reading String
1 gets ( name ) ;

9
EE203ESC05 Computer Programming

4. UNIT 4 : Functions
4.1. Concept of Functions
A function is a block of code used to perform a specific task.

Advantages
• Code reusability
• Easy debugging
• Modular programming

4.2. Syntax of Function


1 return_type function_name ( parameters )
2 {
3 statements ;
4 return value ;
5 }

4.3. Function Example


1 int add ( int a , int b )
2 {
3 return a + b ;
4 }

4.4. void Function


1 void display ()
2 {
3 printf ( " Hello " ) ;
4 }

4.5. Library Functions


• printf()
• scanf()
• strlen()
• strcpy()
• strcat()
• strcmp()
• sqrt()

10
EE203ESC05 Computer Programming

4.6. String Functions


Function Work
strlen() Length of string
strcpy() Copy string
strcat() Join strings
strcmp() Compare strings

5. UNIT 5 : Pointers
5.1. Introduction to Pointers
A pointer is a variable that stores memory address of another variable.

Declaration
1 int * ptr ;

Initialization
1 ptr = & x ;

Dereferencing
1 * ptr

5.2. Pointer Diagram

x = 10 ptr

5.3. Pointer Arithmetic


Increment
N ew Address = Current Address + Size of Datatype

5.4. Call by Value


Original value does not change.

5.5. Call by Reference


Original value changes because address is passed.

11
EE203ESC05 Computer Programming

Swap Example
1 void swap ( int *a , int * b )
2 {
3 int temp ;
4 temp =* a ;
5 * a =* b ;
6 * b = temp ;
7 }

6. UNIT 6 : Structures and File Handling


6.1. Structure
A structure is a user-defined datatype used to group different datatypes.

Syntax
1 struct Student
2 {
3 int roll ;
4 char name [20];
5 float marks ;
6 };

6.2. Declaring Structure Variable


1 struct Student s1 ;

6.3. Accessing Members


1 s1 . roll

6.4. Array of Structures


1 struct Student s [10];

6.5. File Handling


File handling is used to store data permanently.

Opening a File
1 fp = fopen ( " file . txt " ," r " ) ;

12
EE203ESC05 Computer Programming

File Modes
Mode Meaning
r Read
w Write
a Append

File Functions
Function Work
fopen() Open file
fclose() Close file
fprintf() Write data
fscanf() Read data

7. Most Important Programs for Exam


1. Grade Calculation using else-if ladder

2. Even/Odd Program

3. Sum of Array

4. Average of Array

5. Min/Max in Array

6. Searching in Array

7. Function with Return Value

8. Swap using Call by Reference

9. Structure Student Record

10. File Read and Write Program

8. Exam Strategy for 40+/60


Priority Order
1. Control Structures

2. Arrays

3. Pointers

4. Structures and File Handling

5. Functions

6. Basics

13
EE203ESC05 Computer Programming

How to Attempt 6 Mark Questions


1. Definition

2. Syntax

3. Explanation

4. Program

5. Output

6. Conclusion

9. Conclusion
These notes are prepared strictly according to:

• Uploaded Unit Notes

• Previous Year Papers

• Latest Mid Semester Question Papers

If practiced properly along with programs, these notes are sufficient to score 40+/60
comfortably.

Best of Luck

14

You might also like