🖼️Chapter 3 cover
Nepal Engineering Council · Registration ExaminationACtE · Ch 3
← Back to ACtE Syllabus
3

Chapter 3

Programming Language and Its Applications

ACTE03·6 Sub-topics·60 MCQs
🎯 Read MCQs Mode
3.1

Introduction to C Programming

ACtE0301
1
This section covers the building blocks of C programming: tokens and operators, input/output, control and looping statements, user-defined and recursive functions, arrays, and string manipulation.
2
Tokens & Operators C Token Type Examples Keywords Reserved words with fixed meaning: int, if, while, return, etc.
3
Identifiers User-defined names for variables, functions, arrays Constants Fixed values: integer, floating-point, character, string constants Operators Arithmetic (+ − * / %), relational (==, <, >), logical (&&, ||, !), bitwise (&, |, ^, ~, <<, >>), assignment (=, +=), increment/decrement (++, −−) Input/Output Formatted I/O: printf() and scanf() use format specifiers (%d, %f, %c, %s) to read/write data in a specified format.
4
Unformatted I/O: getchar()/putchar() (single character), gets()/puts() (strings) — read/write data without format specifiers.
5
Control & Looping Statements Construct Use if / if-else / nested if / switch Conditional branching based on a Boolean or multi-way condition for loop Iterates a known number of times; combines initialization, condition, and increment in one statement while loop Entry-controlled loop; condition tested before each iteration (may execute zero times) do-while loop Exit-controlled loop; condition tested after each iteration (always executes at least once) break / continue break exits the nearest enclosing loop/switch; continue skips to the next iteration Functions A user-defined function is a self-contained block performing a specific task, improving modularity and code reuse; declared with a return type, name, and parameter list.
6
Recursive function: a function that calls itself, with a base case to terminate recursion and a recursive case that reduces the problem toward the base case (e.g. factorial, Fibonacci).
7
Arrays & Strings 1-D array: a linear collection of elements of the same type, accessed by a single index.
8
2-D / multi-dimensional array: arranged as a matrix (rows/columns) or higher-dimensional grid, accessed with multiple indices.
9
Strings in C are arrays of characters terminated by a null character ('\0'); manipulated using library functions (strlen, strcpy, strcat, strcmp) from <string.h>.
3.2

Pointers, Structures & Data Files in C

ACtE0302
1
This section covers pointer arithmetic and its relationship to arrays, passing pointers to functions, structures and unions, arrays/passing of structures, and file input/output including sequential and random access.
2
Pointers A pointer is a variable that stores the memory address of another variable.
3
Pointer arithmetic: incrementing/decrementing a pointer moves it by the size of the data type it points to (e.g. p+1 on an int* moves 4 bytes on a typical system), not by 1 byte.
4
Pointer and array relationship: an array name decays to a pointer to its first element; arr[i] is equivalent to *(arr+i).
5
Passing pointer to function: allows a function to modify the caller's variable directly (pass-by-reference behavior), and allows efficient passing of large data structures without copying.
6
Structures & Unions Concept Description Structure (struct) Groups variables of different types under one name; each member has its own separate memory Union Groups variables of different types under one name, but all members share the same memory location (only one member holds a valid value at a time), saving memory Array of structures A collection of structure variables of the same type, accessed by index like a normal array Passing structure to function A structure can be passed by value (a copy is made) or by pointer/reference (original is accessible/modifiable) Structure and pointer A pointer to a structure accesses members using the arrow operator (ptr->member) instead of the dot operator File Handling in C File operations use a FILE pointer obtained via fopen() (modes: "r" read, "w" write, "a" append, plus binary variants "rb"/"wb"), and closed with fclose().
7
Sequential access: data is read/written in order from the beginning of the file to the end (e.g. using fscanf/fprintf or fread/fwrite in sequence).
8
Random access: allows jumping directly to any position in the file using fseek() (and reporting position with ftell()), without reading through preceding data.
3.3

C++ Constructs with Objects & Classes

ACtE0303
1
This section covers core C++ language features beyond C — namespaces, function overloading, classes and objects, constructors/destructors, dynamic memory allocation, and special member functions such as static and friend.
2
Core C++ Features Feature Description Namespace A named scope that groups related identifiers, avoiding name clashes between different parts of a program or libraries Function overloading Multiple functions with the same name but different parameter lists (number/type); resolved at compile time based on the arguments passed Inline function Requests the compiler to substitute the function's code directly at the call site, avoiding call overhead for small, frequently-used functions Default argument A parameter is given a default value used automatically if the caller omits that argument Pass/return by reference Uses & to alias a variable, avoiding the overhead of copying and allowing the called function to directly modify the caller's variable Classes & Objects A class is a user-defined blueprint/type combining data (member variables) and behavior (member functions); an object is an instance of a class.
3
Access specifiers: private (accessible only within the class), protected (accessible within the class and derived classes), public (accessible from anywhere the object is visible).
4
Objects access members using the dot operator; member functions can be defined inside the class body or outside using the scope resolution operator (::).
5
Constructors, Destructors & Memory Concept Description Constructor Special member function automatically called when an object is created, used to initialize it; types include default, parameterized, and copy constructors Destructor Special member function automatically called when an object is destroyed, used to release resources; a class has only one destructor, taking no parameters Dynamic memory allocation (new/delete) Objects (and object arrays) can be allocated on the heap at runtime using new, and released using delete, giving control over object lifetime beyond simple scope this pointer An implicit pointer available in every non-static member function, pointing to the object on which the function was called Static, Const, Friend Static data member: shared by all objects of the class (one copy exists regardless of object count).
6
Static function: can be called without an object and can access only static members.
7
Constant member function: guarantees it will not modify the object's data members; a constant object can only call constant member functions.
8
Friend function/class: a non-member function or an entire other class granted access to a class's private/protected members, breaking encapsulation selectively for tightly coupled operations.
3.4

Features of Object-Oriented Programming

ACtE0304
1
This section covers operator overloading, type/data conversion, and the various forms of inheritance in C++, along with how constructors and destructors behave in single and multilevel inheritance hierarchies.
2
Operator Overloading Operator overloading redefines the behavior of an existing operator (e.g. +, ==, <<) for objects of a user- defined class, making custom types behave like built-in types.
3
Unary operator overloading: overloads operators that act on a single operand (e.g. unary minus −, increment ++).
4
Binary operator overloading: overloads operators that act on two operands (e.g. +, −, ==), typically implemented as a member function (implicit left operand) or a friend function (both operands explicit).
5
Data/Type Conversion Conversion between built-in and class types can be achieved using a converting (single-argument) constructor (built-in → class) or an overloaded conversion operator function (class → built-in/another class).
6
Inheritance Inheritance Type Description Single inheritance One derived class inherits from exactly one base class Multiple inheritance One derived class inherits from more than one base class directly Multilevel inheritance A chain: a class derives from a base class, and another class derives from that derived class Hierarchical inheritance Multiple derived classes inherit from a single common base class Hybrid inheritance A combination of two or more inheritance types (e.g. multilevel + multiple) Multipath inheritance A derived class inherits from two base classes that themselves share a common base — can cause ambiguity (the diamond problem), resolved using virtual base classes Constructors/Destructors in Inheritance In single inheritance, when a derived class object is created, the base class constructor executes first, then the derived class constructor; destructors execute in the reverse order (derived first, then base).
7
In multilevel inheritance, constructors execute in order from the topmost base class down to the most- derived class; destructors execute in the exact reverse order.
3.5

Pure Virtual Function & File Handling

ACtE0305
1
This section covers virtual functions and dynamic binding (the basis of runtime polymorphism), C++ file handling operations and error handling, and the stream class hierarchy used for both console and file I/O with formatting manipulators.
2
Virtual Functions & Dynamic Binding Concept Description Virtual function A base class member function declared with the 'virtual' keyword, allowing a derived class to override it so the correct version is called based on the object's actual type, not the pointer/reference type Pure virtual function A virtual function with no implementation in the base class (declared as = 0), forcing any derived class to provide its own implementation; a class containing one becomes abstract (cannot be instantiated) Dynamic binding (late binding) The decision of which function implementation to call is deferred until runtime, based on the actual object type, as opposed to static (compile-time) binding File Handling in C++ File streams are opened via objects of ifstream (input), ofstream (output), or fstream (both), typically using the open() member function or the constructor directly; closed with close().
3
Error handling during I/O: stream state flags (good(), eof(), fail(), bad()) let a program detect and respond to end-of-file conditions or I/O errors.
4
Stream Class Hierarchy The C++ I/O system is built on a class hierarchy rooted at ios, with istream (input), ostream (output), and iostream (both) as key derived classes; cin, cout, cerr are predefined objects of these classes for console I/O.
5
Unformatted I/O uses functions like get()/put() for raw character-level input/output.
6
Formatted I/O uses ios member functions and flags (width(), precision(), setf()/unsetf()) to control field width, number base, precision, and alignment.
7
Manipulators (e.g. endl, setw(), setprecision(), hex, oct) provide a convenient inline way to format stream output directly within an insertion (<<) statement.
3.6

Generic Programming & Exception Handling

ACtE0306
1
This final section of the chapter covers C++ templates (function and class) for generic programming, the Standard Template Library (STL), and the constructs used for robust exception handling.
2
Templates Concept Description Function template A blueprint for a function that works with any data type; the compiler generates a specific version for each type actually used Overloading function template Multiple templates (or a template and a regular function) with the same name can coexist, with the best match chosen for a given call Class template A blueprint for a class that works with any data type, enabling generic data structures (e.g. a generic Stack<T>) Function definition of class template Member functions of a class template are themselves defined as templates, typically outside the class using the scope resolution operator with the template parameter Standard Template Library (STL) STL Component Role Containers Generic data structures storing collections of objects: vector, list, deque, set, map, etc.
3
Algorithms Generic functions operating on containers via iterators: sort, search, find, count, etc.
4
Iterators Generalized pointers that traverse container elements uniformly, connecting algorithms to containers regardless of the underlying container type Exception Handling try/catch/throw: code that might raise an error is placed in a try block; throw signals an exception; a matching catch block handles it.
5
Multiple exception handling: a single try block can be followed by multiple catch blocks, each handling a different exception type.
6
Rethrowing an exception: a catch block can re-throw the caught exception (using throw; with no operand) to let an outer handler process it further.
7
Catching all exceptions: catch(...) matches any exception type, useful as a final fallback handler.
8
Exception with arguments: a thrown object can carry data (e.g. an error code/message) that the catch block's parameter receives.
9
Exception specification: a function declaration can (in older C++) list the exception types it may throw; modern C++ instead commonly uses noexcept to indicate a function throws nothing.
10
Uncaught/unexpected exceptions: if no matching catch handles a thrown exception, terminate() is invoked, ending the program (by default via abort()).