🖼️Chapter 4 cover
Nepal Engineering Council · Registration ExaminationAEE · Ch 4
← Back to AEE Syllabus
4

Chapter 4

Computer Programming

AEEE04·6 Sub-topics·60 MCQs
🎯 Read MCQs Mode
4.1

Introduction to Programming

AEEE0401
1
This section covers programming fundamentals — tokens, data types, variables, constants, operators, formatted/unformatted I/O, structured vs object-oriented programming, and algorithms & flowcharts.
2
Tokens, Data Types & Variables A token is the smallest individual unit of a program — keywords, identifiers, constants, operators, and punctuation/special symbols (comments are stripped out and are NOT tokens).
3
Common data types: int (integers), float/double (decimals), char (single character), void (no value).
4
A variable is a named memory location whose value can change; declared as type name;
5
Numeric (e.g., 25, 3.14), Character (e.g., 'A'), String (e.g., "Hello") — values that do not change during execution.
6
Operators Category Examples Arithmetic + − * / % (modulus) Assignment = += −= *= /= Relational / Comparison == != < > <= >= Logical && (AND) || (OR) ! (NOT) Input & Output Statements Formatted I/O (e.g., printf()/scanf() in C): uses format specifiers — %d (int), %f (float), %c (char), %s (string).
7
Unformatted I/O (e.g., getchar()/putchar(), gets()/puts()): reads/writes raw characters or strings without format conversion.
8
Structured vs Object-Oriented Programming Paradigm Approach Structured programming Program organized top-down around functions/procedures that operate on separately declared data (e.g., C) Object-oriented programming (OOP) Data and the functions that operate on it are bound together into objects/classes (e.g., C++, Java) Algorithms & Flowcharts An algorithm is a finite, step-by-step procedure for solving a problem, independent of any programming language.
9
A flowchart represents an algorithm graphically using standard symbols: oval (start/end), rectangle (process), diamond (decision), parallelogram (input/output).
4.2

Control Statements

AEEE0402
1
This section covers decision-making statements (if, if-else, switch), loop statements (for, while, do-while), and control-breaking statements (break, continue, goto).
2
Decision-Making Statements Statement Behaviour if Executes a block only if the condition is true if-else Executes one block if the condition is true, another if false Nested if- else Tests multiple conditions in sequence, one inside another switch-case Selects one of several blocks to execute based on the value of a single variable/expression; typically uses break to prevent fall-through, and a default case for no match Loop Statements Loop Type Key Feature for loop Entry- controlled Combines initialization, condition, and increment/decrement in one line — ideal when the number of iterations is known while loop Entry- controlled Condition tested BEFORE each iteration — may execute zero times do-while loop Exit- controlled Condition tested AFTER each iteration — body always executes at least once Breaking Control Statements break: immediately exits the enclosing loop or switch statement. continue: skips the remaining code in the current iteration and proceeds to the next iteration of the loop. goto: performs an unconditional jump to a labeled statement; generally discouraged as it can make code harder to follow (“spaghetti code”).
4.3

Functions

AEEE0403
1
This section covers function definition and use, function prototypes, argument-passing methods, and recursive functions.
2
Defining & Using Functions A function is a self-contained block of code that performs a specific task; using functions promotes modularity and code reusability.
3
A function prototype declares a function's return type, name, and parameter types before it is used/defined, allowing the compiler to check calls for correctness.
4
A function with no return value uses the return type void.
5
Local variables declared inside a function are accessible only within that function (scope is local).
6
Passing Arguments to a Function Method Behaviour Call by value A COPY of the argument's value is passed; changes inside the function do NOT affect the original variable Call by reference (pointer) The ADDRESS of the argument is passed; changes inside the function DO affect the original variable Passing an array to a function effectively passes a pointer to its first element (not a full copy) — so changes to array elements inside the function DO affect the original array.
7
Recursive Functions A recursive function is one that calls itself to solve smaller instances of the same problem (e.g., factorial, Fibonacci).
8
Every recursive function MUST have a base case that stops further recursive calls — without one, it will recurse indefinitely (stack overflow).
9
Recursive functions typically consume more stack memory than an equivalent iterative (loop-based) solution, due to repeated function-call overhead.
4.4

Pointers & Data Files

AEEE0404
1
This section covers pointer declaration and arithmetic, the relationship between pointers and arrays, and dynamic memory allocation.
2
Pointer Basics A pointer is a variable that stores the ADDRESS of another variable, rather than a data value directly.
3
Declaration: type *ptr;
4
(e.g., int *p; declares a pointer to an int).
5
The & (address-of) operator returns a variable's address; the * (dereference) operator accesses the value stored at the address a pointer holds.
6
Pointer Arithmetic Incrementing a pointer (ptr++) moves it forward by sizeof(pointed-to type) bytes — not necessarily 1 byte.
7
Subtracting two pointers of the same type gives the NUMBER OF ELEMENTS between them (not the raw byte difference).
8
Pointers & Arrays In C, an array name used in an expression generally decays into a pointer to its first element. arr[i] is equivalent to the pointer expression *(arr + i).
9
Dynamic Memory Allocation Function/Keyword Purpose (Language) malloc() Allocates a block of uninitialized memory at runtime (C) calloc() Allocates and zero-initializes memory for an array of elements (C) realloc() Resizes a previously allocated memory block (C) free() Releases (deallocates) previously allocated dynamic memory (C) new / delete Allocate / deallocate memory dynamically (C++) Dynamic memory allocation lets a program request and release memory at RUNTIME, rather than fixing all memory needs at compile time — essential for data structures whose size is not known in advance.
4.5

Arrays & Structures

AEEE0405
1
This section covers array definition, processing and passing to functions, multidimensional arrays, and structures — including arrays of structures and pointers to structures.
2
Arrays An array is a collection of elements of the SAME data type, stored in contiguous memory locations and accessed by an index.
3
Processing an array typically uses a loop to visit each element by index (e.g., for (i=0; i<n; i++)).
4
When an array is passed to a function, it is passed effectively BY REFERENCE (as a pointer to its first element) — not as a full copy.
5
A multidimensional array (e.g., a 2D array) can be thought of as an array of arrays — commonly used to represent matrices and tables of data.
6
Structures A structure (struct) is a user-defined data type that groups variables of DIFFERENT data types under a single name — unlike an array, which holds only one data type.
7
Structure members can be initialized at the time of declaration using an initializer list.
8
Concept Description Array of structures A collection of structure variables (records), each sharing the same layout — e.g., a list of student records Pointer to structure A pointer that holds the address of a structure variable; members are accessed using the -> (arrow) operator Structure members are accessed directly with the .
9
(dot) operator; through a pointer, with the -> (arrow) operator.
4.6

Features of Object-Oriented Programming

AEEE0406
1
This section covers key object-oriented programming features: inline functions, function overloading, classes and objects, member functions, static members, operator overloading, inheritance and polymorphism.
2
Classes & Objects A class is a blueprint/template that defines data members and member functions; an object is a concrete INSTANCE of a class.
3
Access specifiers control visibility of members: private (accessible only within the class's own member functions, by default), public (accessible from anywhere), protected (accessible within the class and its derived classes).
4
A private member function can be called only from within the class's own member functions, not directly from outside code.
5
A constructor is a special member function used to initialize an object automatically when it is created.
6
Inline Functions & Function Overloading An inline function is expanded directly at the point of call (avoiding function-call overhead) — suitable for small, frequently used functions.
7
Function overloading allows multiple functions to share the same name but differ in their parameter list (number/type of parameters) — a form of compile-time polymorphism.
8
Static Data Members & Static Member Functions Feature Behaviour Static data member A SINGLE copy is shared among ALL objects of the class (not unique per object) Static member function Can be called WITHOUT creating an object of the class; can only directly access other static members Operator Overloading, Inheritance & Polymorphism Operator overloading lets a programmer redefine how existing operators (e.g., +, ==) behave for user- defined (class) types — it cannot be used to invent entirely new operators.
9
Inheritance allows a derived (child) class to acquire the properties and behaviours of a base (parent) class, promoting code reuse and establishing an “is-a” relationship.
10
Polymorphism is the ability of a function or object to take multiple forms — achieved at COMPILE time via overloading, or at RUN time via overriding/virtual functions.