๐Ÿ–ผ๏ธChapter 3 cover
Nepal Engineering Council ยท Registration ExaminationASoE ยท Ch 3
โ† Back to ASoE Syllabus
3

Chapter 3

Programming Language and Its Applications

ASOE03ยท6 Sub-topicsยท60 MCQs
๐ŸŽฏ Read MCQs Mode
3.1

Procedure and parallel programming languages

ASoE0301
1
Procedural languages (C, Pascal, FORTRAN) organize a program as a sequence of instructions/procedures that operate step-by-step on data.
2
Data types are classified as Primitive/basic (int, float, char, boolean), Derived (array, pointer, structure), and User-defined (enum, typedef, class).
3
An Abstract Data Type (ADT) is defined purely by the operations it supports (its behavior), NOT by how it is implemented internally โ€” e.g. Stack, Queue, and List are ADTs; a Stack ADT is defined by push/pop regardless of whether it uses an array or a linked list.
4
Structured programming organizes a program using exactly three basic control structures: Sequence (statements executed in order), Selection (if/switch), and Iteration (loops) โ€” improving readability, testability, and reuse.
5
**Syntax** is the set of grammatical rules defining how valid statements/programs must be written, while **Semantics** is the meaning of a syntactically correct statement โ€” i.e. what it actually does when it runs.
6
A user-defined function is a block of code written by the programmer to perform a specific task; it is invoked through a function call and may return a value to the caller.
7
A recursive function is a function that calls itself, either directly or indirectly, to solve a problem by breaking it into smaller sub-problems (e.g. factorial, Fibonacci).
8
Every recursive function needs a base case to terminate the recursion; each call adds a new activation record onto the call stack until the base case is reached.
9
Arrays: a 1-D array is a single row/list accessed by one index (arr[i]); a 2-D array is a table of rows x columns accessed by two indices (arr[i][j]); a multi-dimensional array uses three or more indices (arr[i][j][k]).
10
In C, a string is an array of characters terminated by the null character '\0'; key library functions are strlen() (length), strcpy() (copy), strcat() (concatenate), and strcmp() (compare).
11
The RAM (Random Access Machine) model is an idealized single-processor computer used for analyzing algorithms: it assumes every simple operation (arithmetic, comparison, assignment, or memory access) takes a constant amount of time, O(1), letting running time be measured simply by counting elementary steps, independent of real hardware speed.
12
Concurrency means multiple computations are in progress during overlapping time periods, potentially executing simultaneously on multiple processors (parallelism); processes then communicate either via **message passing** (explicit send/receive, used in loosely coupled/distributed systems with no shared memory) or **shared memory** (a common memory area, used in tightly coupled multiprocessor systems, requiring synchronization).
13
The PRAM (Parallel Random Access Machine) is a theoretical model for parallel algorithm analysis, assuming multiple processors share a common memory with uniform, unit-time access.
14
A Monitor encapsulates shared data together with the procedures that operate on it, and the language/runtime automatically enforces mutual exclusion between those procedures, whereas a Semaphore is an integer synchronization variable manipulated only by the atomic wait() (P) and signal() (V) operations, used to control access to shared resources.
3.2

Exception handling in various languages

ASoE0302
1
An exception is an abnormal condition that disrupts the normal flow of a program during execution.
2
A checked exception must be declared/handled at compile time (e.g. Java's IOException) โ€” the compiler forces the programmer to deal with it.
3
An unchecked (runtime) exception is not mandatory to handle and is detected only at run time (e.g. NullPointerException, ArithmeticException/divide-by-zero).
4
An Error is a serious problem usually outside application control (e.g. OutOfMemoryError, StackOverflowError); normally NOT meant to be caught/handled by application code.
5
The try block encloses code that might throw an exception; catch catches and handles a specific type of exception thrown from the try block.
6
throw is used to explicitly raise/signal an exception; finally is a block that always executes whether or not an exception occurred โ€” used for cleanup such as closing files or connections.
7
General flow: code that might fail is placed in a try block; if an exception occurs, control jumps to the matching catch block; a finally block (where supported) runs regardless of the outcome, ensuring resources are always released.
8
An event is an action or occurrence recognized by a program โ€” e.g. a mouse click, a key press, a timer tick, or even an exception being raised.
9
Event-driven programming structures a program around responding to events via event handlers/listeners, rather than executing a fixed top-to-bottom sequence.
10
When working with large databases, robust exception handling is essential to catch connection failures, query timeouts, and constraint violations, and to safely roll back an incomplete transaction rather than leave data in an inconsistent state.
11
C++ uses try/catch/throw โ€” it has NO built-in `finally`; RAII (Resource Acquisition Is Initialization) is used for cleanup instead.
12
Java uses try/catch/finally, with a strict distinction between checked and unchecked exceptions.
13
Python uses try/except/finally, with exceptions raised using the raise keyword โ€” unlike Java/C++'s `catch`, Python uses except.
14
C# uses try/catch/finally, similar in structure to Java.
3.3

Pointers, structure and data files in C programming

ASoE0303
1
A pointer is a variable that stores the memory address of another variable.
2
Pointer arithmetic: incrementing/decrementing a pointer moves it by sizeof(type) bytes, NOT by 1 byte โ€” e.g. for an int pointer, ptr+1 advances by 4 bytes (on a typical system) to point to the next int.
3
Pointer and array: an array name behaves as a constant pointer to its first element; the expression arr[i] is equivalent to *(arr + i).
4
Passing a pointer to a function lets the function access and modify the caller's actual variable directly (simulating call-by-reference in C), and avoids the overhead of copying large data such as arrays or structures.
5
**Structure**: each member gets its own separate memory, so its total size is the sum of all members' sizes (plus padding), and all members hold valid data simultaneously โ€” used for grouping related but different fields (e.g. a record).
6
**Union**: all members share the same memory location, so its size equals the size of its largest member, and only ONE member holds valid data at any given time โ€” used to save memory when only one of several fields is needed at a time.
7
An array of structures is a collection of structure variables of the same type, ideal for representing multiple records (e.g. an array of student records).
8
A structure can be passed to a function by value (the whole structure is copied) or by reference/pointer (only the address is passed, more efficient for large structures).
9
When a pointer refers to a structure, its members are accessed using the arrow operator (->) instead of the dot operator, e.g. ptr->member.
10
File I/O functions: fopen()/fclose() open/close a file (associating it with a FILE pointer); fprintf()/fscanf() do formatted write/read; fgetc()/fputc() read/write a single character; fgets()/fputs() read/write a line of text; fread()/fwrite() read/write raw binary data blocks.
11
Common file-open modes: r (read), w (write/overwrite), a (append), r+, w+, a+ (read+write variants), and their binary forms rb, wb, ab, etc.
12
Sequential access reads or writes data strictly in order, from the start of the file onward (typical usage of fscanf/fprintf, fgets/fputs).
13
Random access allows jumping directly to any position in the file, using fseek() (move the file pointer), ftell() (report the current position), and rewind() (reset the pointer to the beginning).
3.4

Object-oriented programming concepts

ASoE0304
1
A class is a blueprint/template that defines data members (attributes) and member functions (behavior); an object is a concrete instance created from a class. A namespace is a declarative region that scopes the identifiers inside it, preventing naming conflicts between different parts of a large program (e.g. the std namespace in C++).
2
Function overloading: multiple functions share the same name but differ in the number/type of parameters; the compiler selects the correct one at compile time (compile-time/static polymorphism).
3
An inline function is a request to the compiler to substitute the function's code directly at the call site, avoiding function-call overhead; best suited to small, frequently called functions.
4
A default argument is a parameter assigned a default value in the function declaration, used automatically when the caller omits that argument.
5
Pass/return by reference uses & to pass or return the actual variable rather than a copy, allowing the callee to modify the caller's data and avoiding copy overhead.
6
Access specifiers: private (accessible only from within the same class), protected (the same class and its derived/child classes), public (accessible anywhere the object is visible).
7
**Static (compile-time) polymorphism** is resolved at compile time and achieved via function/operator overloading, while **Dynamic (run-time) polymorphism** is resolved at run time and achieved via method overriding using virtual functions (vtable-based dispatch).
8
Method overriding occurs when a derived class provides its own implementation of a (virtual) function already defined in its base class, using the same name and signature.
9
Libraries/Packages are reusable collections of pre-written classes and functions (e.g. the C++ Standard Template Library, Java's java.util package); an Interface defines a contract of methods a class must implement, without providing any implementation itself (a pure abstract class in C++, the interface keyword in Java).
10
Abstraction shows only the essential features of an object while hiding complex implementation details; Encapsulation bundles data and the methods that operate on it together within a single class; Data hiding restricts direct external access to an object's internal data, typically by making data members private.
11
A constructor shares the class's name, has no return type, and is called automatically when an object is created (types: default, parameterized, copy constructor); a destructor is named ~ClassName, has no return type or parameters, is called automatically when an object is destroyed/goes out of scope, and is used mainly for cleanup (releasing resources, memory).
12
Garbage collection is automatic memory management that reclaims the memory of objects no longer referenced by the program (built into Java/C#); C++ has NO automatic garbage collector, so dynamically allocated memory must be released manually with delete.
13
Dynamic memory allocation for objects/object arrays uses new/delete in C++ (malloc()/free() in C), allocating memory at run time from the heap; the this pointer is an implicit pointer available inside every non-static member function, pointing to the object on which the function was called.
14
A static data member is shared by all objects of a class โ€” only one copy exists regardless of how many objects are created โ€” and a static member function can access only static members and can be called without any object; a friend function/class is a non-member function or class explicitly granted access to a class's private and protected members, even though it is not itself a member.
3.5

Streams, file handling

ASoE0305
1
C++ provides three main file-stream classes: ifstream (input file stream, for reading), ofstream (output file stream, for writing), and fstream (both reading and writing).
2
A file can be opened either via the stream object's constructor or explicitly with its open() member function, and must be closed with close() once finished, to flush buffers and release the file handle.
3
Data can be read/written using the insertion (<<) and extraction (>>) operators, or member functions such as get(), put(), read(), and write().
4
Error handling during I/O relies on internal stream state flags: goodbit (no error), eofbit (end of file reached), failbit (a logical/format error occurred), and badbit (a serious/irrecoverable error) โ€” checked with member functions good(), eof(), fail(), bad(), and reset with clear().
5
The base class ios provides common stream functionality; istream (input) and ostream (output) derive from it, and iostream combines both for bidirectional streams.
6
cin is a predefined object of class istream (standard input); cout is a predefined object of class ostream (standard output); cerr/clog handle error output.
7
**Unformatted I/O** reads/writes raw data with no formatting applied, using functions such as get(), put(), read(), write(), while **Formatted I/O** applies formatting (width, precision, base, fill character) using ios member functions/flags and manipulators.
8
Manipulators are defined mainly in the header <iomanip>: endl (newline + flush), setw() (field width), setprecision() (decimal precision), setfill() (fill character), and base/format manipulators hex, oct, dec, fixed, showpoint.
9
Every file stream maintains a get pointer (g) for the next read position and a put pointer (p) for the next write position.
10
seekg()/seekp() move the get/put pointers to a specific byte offset (enabling random access); tellg()/tellp() report their current positions.
11
Sequential access simply reads/writes from the current pointer position onward in order; random access uses seekg()/seekp() to jump directly to any byte offset in the file.
3.6

Templates

ASoE0306
1
Templates enable generic programming in C++, allowing functions and classes to work with any data type.
2
A function template is a blueprint for creating a family of generic functions that work with any data type, defined using template<class T> or template<typename T> before the function definition.
3
The compiler automatically generates a specific version of the function for each data type it is actually called with โ€” a process called template instantiation.
4
Function templates can themselves be overloaded โ€” multiple template (or a mix of template and ordinary) functions can share the same name but differ in their parameter lists.
5
When a call is made, the compiler picks the best match, generally preferring a non-template (ordinary) function over a template if both match equally well.
6
A class template is a blueprint for generic classes, letting the class operate on a generic type parameter instead of one fixed type โ€” e.g. template<class T> class Stack ... ; can create Stack<int>, Stack<float>, Stack<string>, etc.
7
Member functions of a class template are defined outside the class body using the syntax template<class T> ReturnType ClassName<T>::functionName(...) ... , so each member function remains templated on the same type parameter as the class.
8
STL Containers are generic data structures that store collections of objects โ€” vector, list, stack, queue, map, set.
9
STL Algorithms are generic functions that operate on containers via iterators โ€” sort(), find(), reverse(), count().
10
STL Iterators are objects that behave like generalized pointers, used to traverse the elements of a container.
11
The STL is built almost entirely using templates, which is what allows a single container or algorithm implementation to work seamlessly with any data type.