πŸ–ΌοΈ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
C tokens are the smallest units of a program: keywords (reserved words like int, float, if, for, return β€” ANSI C defines 32 keywords), identifiers (user-defined names for variables, functions, and arrays that must start with a letter or underscore), constants, strings, operators, and special symbols.
2
Constants are fixed values β€” integer, floating-point, character, and enumeration constants; a string is a sequence of characters in double quotes, always terminated by the null character `'\0'`.
3
Operators are symbols that perform arithmetic, relational, logical, bitwise, or assignment operations; special symbols include braces `, parentheses (), semicolon ;`, and comma.
4
Basic data types are int, float, double, char, void; type modifiers short, long, signed, unsigned change the size/range of a base type.
5
Operator precedence (highest to lowest): () > unary (++ -- !) > * / % > + - > relational > logical > assignment (=).
6
Formatted I/O (printf(), scanf()) uses format specifiers %d, %f, %c, %s, %ld, etc.; unformatted I/O β€” getchar()/putchar() (single character) and gets()/puts() (strings) β€” needs no format specifier.
7
Decision-making constructs: if, if-else, nested if-else, else-if ladder, switch-case (works on int/char); `switch-case` needs `break` to prevent fall-through into the next case.
8
for(initialization; condition; increment) checks its condition before each iteration, making the for loop entry-controlled.
9
`while` is entry-controlled (condition tested before the body, so it may run zero times); `do-while` is exit-controlled, executing the body at least once before testing the condition.
10
break exits the loop/switch entirely; continue skips to the next iteration; goto performs an unconditional jump.
11
A function has a declaration (prototype), definition, and call; C uses call by value by default, passing a copy of the argument so the caller's original variable is unchanged.
12
A recursive function calls itself and must have a base case to terminate β€” without one it causes infinite recursion / stack overflow (e.g., factorial, Fibonacci).
13
Arrays are stored in contiguous memory and are 0-indexed: 1-D int a[5];, 2-D int a[3][4] (rows Γ— columns); multi-dimensional arrays extend the same pattern.
14
Strings are character arrays terminated by '\0'; common string.h functions include strlen(), strcpy(), strcat(), strcmp(), strrev().
3.2

Pointers, structure and data files in C programming

ACtE0302
1
A pointer is a variable that stores the address of another variable, declared with * (e.g., int *p;); the & operator gives the address of a variable.
2
Pointer arithmetic: incrementing a pointer (p++) moves it forward by sizeof(data type), NOT by 1 byte.
3
An array name is a constant pointer to its first element, so a[i] is equivalent to *(a + i) β€” and since indexing is pointer arithmetic, i[a] also equals the same value.
4
Passing a pointer to a function simulates call by reference β€” the function can modify the caller's original variable through the address it receives.
5
**Structure**: each member has its own separate memory; total size = sum of member sizes; declared with the struct keyword; all members hold valid values simultaneously.
6
**Union**: all members share the same memory location; total size = size of the largest member; declared with the union keyword; only one member holds a valid value at a time.
7
An array of structures (e.g., struct Student s[50];) stores multiple records of the same structure type.
8
A structure can be passed to a function by value (a copy) or by reference/pointer (to allow modification and avoid copying overhead).
9
fopen()/fclose() open and close a file; fopen() returns a FILE pointer.
10
File modes: r, w, a (read / write-overwrite / append, text); r+, w+, a+ (read and write combined); rb, wb, ab (same modes, binary).
11
fprintf()/fscanf() perform formatted write/read to/from a file (text mode); fread()/fwrite() perform binary block read/write of data.
12
fseek(), ftell(), rewind() are used for random access β€” they move/inspect the file pointer position.
13
Sequential access reads/writes a file from beginning to end in order; random access uses fseek() to jump directly to any byte position in the file.
3.3

C++ language constructs with objects and classes

ACtE0303
1
A namespace (e.g., std) groups names to avoid naming conflicts; accessed via the scope resolution operator (std::cout) or a using directive (using namespace std;).
2
Function overloading: multiple functions with the same name but different parameter lists (number/type), resolved at compile time β€” this is compile-time (static) polymorphism.
3
An inline function (declared with inline) requests the compiler substitute the function's code directly at the call site, avoiding function-call overhead β€” best for small, frequently used functions.
4
A default argument assigns a parameter a default value in the function declaration; the caller may omit it and the default is used.
5
Pass/return by reference (using &) avoids copying the argument and lets the called function modify the caller's original variable.
6
Access specifiers: private (default) β€” accessible only within the class itself and its friends; public β€” accessible from anywhere the object is visible; protected β€” accessible within the class and its derived classes.
7
A class is a user-defined blueprint/template; an object is an instance of a class created from it. Member functions may be defined inside the class body or outside using :: (e.g., void Box::setLength(...)).
8
Constructor types: default (no arguments, called automatically when an object is created without initializers), parameterized (arguments initialize specific values), copy (creates a new object as a copy of an existing one).
9
A destructor (~ClassName()) is called automatically when an object is destroyed; it takes no arguments, returns nothing, and cannot be overloaded.
10
Dynamic memory for objects uses new/delete (and new[]/delete[] for arrays), replacing C's `malloc()`/`free()`.
11
The this pointer implicitly refers to the current object, used mainly to resolve naming conflicts between a member and a parameter.
12
A static data member is shared by all objects of the class (one single copy); a static member function can access only static members and is called using the class name.
13
A const member function (declared with const after the parameter list) cannot modify the object's data members; a const object can only call const member functions.
14
A friend function/class is not a member but is granted access to the class's private and protected members.
3.4

Features of object-oriented programming

ACtE0304
1
Operator overloading gives additional, class-specific meaning to an existing operator, defined using the operator keyword (e.g., operator+()).
2
Unary operator overloading involves operators with one operand (++, --, unary minus -); binary operator overloading involves operators with two operands (+, -, ==, <).
3
Data conversion: basic-to-class type uses a constructor; class-to-basic type uses a conversion/casting operator function (e.g., operator int()); class-to-class conversion is also possible.
4
Single inheritance: one derived class inherits from exactly one base class.
5
Multiple inheritance: one derived class inherits from two or more base classes.
6
Multilevel inheritance: a class is derived from a class that is itself derived from another (a chain A β†’ B β†’ C).
7
Hierarchical inheritance: multiple derived classes inherit from a single common base class.
8
Hybrid inheritance combines two or more types of inheritance (e.g., hierarchical + multiple).
9
Multipath inheritance: a derived class inherits the same base class through more than one path, which may cause ambiguity β€” resolved using a virtual base class.
10
Constructor call order in inheritance: the base class constructor executes first, then the derived class constructor.
11
Destructor call order is the reverse of construction: the derived class destructor executes first, then the base class destructor.
3.5

Pure virtual function and file handling

ACtE0305
1
A virtual function is declared with the virtual keyword in the base class and redefined (overridden) in a derived class, enabling runtime (dynamic) polymorphism when called through a base class pointer/reference.
2
A pure virtual function is declared as virtual void fn() = 0;; a class containing at least one pure virtual function becomes an abstract class, which cannot be instantiated directly.
3
Dynamic binding (late binding) means the actual function called is resolved at run time based on the object's real type, rather than at compile time.
4
ios is the base class of the entire stream hierarchy, defining status flags and formatting.
5
istream handles input operations (>>) and is the base of ifstream; ostream handles output operations (<<) and is the base of ofstream.
6
iostream derives from both istream and ostream, supporting both input and output (cin/cout).
7
ifstream reads data from files; ofstream writes data to files; fstream (derived from iostream) supports both reading and writing.
8
Files are opened with the open() member function (or constructor) and closed with close().
9
Error-checking member functions: eof() (end of file reached), fail() (an operation failed), bad() (a serious/unrecoverable error), good() (no error flags set).
10
Formatted I/O uses ios member functions such as width(), precision(), fill(), and flag-setting functions setf()/unsetf() with flags like ios::left, ios::right, ios::showpoint.
11
Manipulators (from <iomanip>) provide formatting shorthand: endl (newline + flush), setw() (field width), setprecision() (decimal precision), setfill() (fill character).
3.6

Generic programming and exception handling

ACtE0306
1
A function template (template<class T>) defines a generic function that works with any data type, avoiding repetitive overloaded code.
2
A template can coexist with ordinary overloaded functions; the compiler chooses the best match.
3
A class template defines a generic class (e.g., a generic Stack<T>) whose member functions can also be defined outside the class using the scope resolution operator.
4
STL has three main components: Containers (vector, list, map, set, stack, queue β€” store data), Algorithms (sort, search, find, etc. β€” operate on containers), and Iterators (pointer-like objects used to traverse container elements).
5
try encloses the block of code that might throw an exception; throw signals (raises) that an exceptional condition has occurred; catch handles the exception thrown in the corresponding try block.
6
Multiple exception handling: a single try block may be followed by several catch blocks, each handling a different exception type.
7
Rethrowing: using throw; (with no operand) inside a catch block passes the exception on to an outer/enclosing handler.
8
catch(...) matches any exception type, regardless of its actual type.
9
An exception can carry data/objects via throw, which the matching catch block receives as a parameter.
10
Exception specification (e.g., void f() throw(int);) historically declared which exception types a function may throw β€” removed/deprecated from modern C++.
11
If no matching catch handles an exception, terminate() is called (historically unexpected() for exception-specification violations); these can be customized with set_terminate()/set_unexpected().