πŸ–ΌοΈChapter 3 cover
Nepal Engineering Council Β· Registration ExaminationAItE Β· Ch 3
← Back to AItE Syllabus
3

Chapter 3

Programming Languages and Web Technology

AITE03Β·6 Sub-topicsΒ·60 MCQs
🎯 Read MCQs Mode
3.1

Introduction to C Programming

AItE0301
1
C is a compiled, procedural language created by Dennis Ritchie at Bell Labs in 1972. It is the parent of C++, Java, and most systems languages β€” learning C well pays off everywhere.
2
C tokens are the smallest meaningful units: keywords (int, if, return), identifiers (variable/function names), constants (3.14, 'A'), string literals ("hello"), operators (+, ==), and punctuators ( , ;).
3
Formatted I/O: printf() writes formatted output; scanf() reads formatted input. Format specifiers: %d (int), %f (float), %c (char), %s (string), %lf (double), %ld (long).
4
Unformatted I/O: getchar()/putchar() for single characters; gets()/puts() for strings. gets() is unsafe β€” use fgets() instead.
5
Control statements: if-else for binary decisions. switch-case for multi-branch selection β€” works only with integral types (int, char), NOT float or double.
6
Three loop types: for (count-controlled), while (condition checked BEFORE body β€” may never execute), do-while (condition checked AFTER body β€” executes AT LEAST ONCE).
7
Functions: reusable named blocks of code. A prototype declares the return type and parameters. C passes arguments by VALUE β€” the function gets a copy, not the original.
8
Recursive function: a function that calls itself. Every recursive function needs a BASE CASE to stop. Without it β†’ infinite recursion and a stack overflow. Classic examples: factorial, Fibonacci.
9
Arrays: a block of CONTIGUOUS memory holding elements of the SAME type. Index starts at 0 β€” an array of size n has indices 0 to n-1. C does NOT check array bounds β€” out-of-bounds access is a silent bug.
10
2D arrays: a[rows][cols] stored in row-major order. Element a[i][j] is at offset i*cols + j from the start.
11
Strings in C are null-terminated char arrays: 'H','e','l','l','o','\0'. The null terminator '\0' marks the end. Key functions from <string.h>: strlen(), strcpy(), strcat(), strcmp(), strncpy().
3.2

Pointers, Structure and Data Files in C

AItE0302
1
A pointer is a variable that stores a MEMORY ADDRESS. Declared with *: int *p; means p holds the address of an int. Pointers are the most powerful β€” and most error-prone β€” feature of C.
2
Two fundamental pointer operators: `&` (address-of) returns the memory address of a variable; ***** (dereference) accesses the VALUE stored at the address.
3
Pointer arithmetic: incrementing a pointer (p++) moves it forward by sizeof(pointed type). So if int *p and sizeof(int)=4, p++ adds 4 to the raw address.
4
Arrays and pointers are deeply linked: the array name is a constant pointer to the first element. a[i] and *(a + i) are completely equivalent.
5
Passing a pointer to a function achieves call-by-reference: the function receives the address, can dereference it, and modify the original variable in the caller.
6
Structure (struct): groups variables of DIFFERENT types under one name. Each member gets its OWN memory. Members are accessed with the `.` (dot) operator.
7
Union: all members SHARE the same memory location. Size = size of the LARGEST member. Only one member can hold valid data at a time.
8
Array of structures: struct Student arr[50]; β€” stores 50 student records contiguously. Accessed as arr[i].name, arr[i].marks.
9
Structure pointer: struct Point *p; β€” use the `->` (arrow) operator to access members: p->x is identical to (*p).x.
10
File I/O: fopen() returns a FILE* pointer (NULL if it fails). fclose() closes it. Text mode: fprintf()/fscanf(); binary mode: fread()/fwrite().
11
File modes: "r" (read only, file must exist), "w" (write, creates or truncates), "a" (append, creates if not exist), "r+" (read and write).
12
Random file access: fseek(fp, offset, whence) moves to a position. whence = SEEK_SET (from start), SEEK_CUR (from current), SEEK_END (from end). ftell() returns current byte position.
3.3

OOP Fundamentals and Frameworks

AItE0303
1
OOP (Object-Oriented Programming) models software around OBJECTS β€” self-contained units combining data (attributes) and behavior (methods). Its four core pillars: Encapsulation, Abstraction, Inheritance, Polymorphism.
2
Encapsulation: bundling data and methods inside a class, while controlling access through access specifiers (private, protected, public). This is data hiding β€” internal details are protected.
3
Abstraction: showing ONLY what the user needs, hiding implementation complexity. A car's accelerator is abstracted β€” you press it; you don't know about fuel injectors.
4
Inheritance: a derived (child) class acquires properties of a base (parent) class β€” the IS-A relationship. A Dog IS-A Animal. Enables code reuse without rewriting.
5
Polymorphism: 'one interface, many implementations'. Compile-time: function overloading, operator overloading. Runtime: virtual functions (method overriding).
6
A class is a blueprint/template; an object is an INSTANCE of that class. class Car ... defines the blueprint; Car c1; creates an actual object.
7
Constructors: special member functions with the SAME name as the class and NO return type. Called AUTOMATICALLY when an object is created. Types: Default, Parameterized, Copy.
8
Destructor: ~ClassName(). Called AUTOMATICALLY when the object is destroyed. A class has exactly ONE destructor. Used for cleanup (freeing memory, closing files).
9
Access specifiers: private (accessible ONLY within the class), protected (within class AND derived classes), public (accessible from ANYWHERE).
10
The `this` pointer: a hidden pointer in every non-static member function pointing to the calling object. Used to disambiguate member names from parameter names.
11
Static data member: a SINGLE copy SHARED by ALL objects of the class. Declared static, defined outside the class. Static member function: can be called without an object (ClassName::func()).
12
Friend function/class: granted special access to a class's private/protected members. Declared inside the class with friend keyword, but NOT a member. Use sparingly β€” it breaks encapsulation.
13
Java: source compiles to bytecode β†’ JVM (Java Virtual Machine) interprets it on any platform ('write once, run anywhere'). JDK βŠƒ JRE βŠƒ JVM.
14
Inline function: compiler replaces the function call with the function body β€” eliminates call overhead for small, frequently-called functions.
3.4

Fundamentals of Web Technology

AItE0304
1
The Web works like this: you type a URL β†’ browser sends an HTTP request to a web server β†’ server sends back HTML/CSS/JS β†’ browser renders the page. The Internet is the network; the WWW is the service that runs on it.
2
Web architecture: Client (browser) ↔ Web Server ↔ Application Server ↔ Database. Static pages: server serves files. Dynamic pages: server runs code (PHP, Python, Node.js) to generate HTML on demand.
3
Email protocols: SMTP (Simple Mail Transfer Protocol) β€” SENDS outgoing mail. POP3 β€” downloads mail to device and deletes from server. IMAP β€” syncs mail; messages STAY on server, accessible from multiple devices.
4
HTTP (Hypertext Transfer Protocol): the foundation of web communication. Key HTTP methods: GET (retrieve data, visible in URL), POST (submit data, hidden in body), PUT (replace/update), DELETE (remove).
5
HTTP is STATELESS β€” each request-response pair is independent. The server remembers nothing between requests. Cookies and sessions solve this.
6
HTTPS = HTTP + TLS (Transport Layer Security) encryption. The 's' means data is encrypted in transit β€” secure login, banking, shopping. Identified by https:// and the padlock icon.
7
Client-side scripts run in the USER'S browser (JavaScript). They can modify the page dynamically without reloading (DOM manipulation). Fast, interactive β€” no server round-trip.
8
Server-side scripts run on the WEB SERVER (PHP, Python, Node.js). The user never sees the source. Used for database queries, authentication, dynamic content generation.
9
JavaScript (JS): the language of the web browser. Manipulates the DOM, handles events (clicks, inputs), makes AJAX calls to fetch data without page reload.
10
PHP (Hypertext Preprocessor): server-side language embedded directly in HTML (<?php ... ?>). Connects to databases (MySQL/MariaDB), handles sessions, cookies, and CRUD operations.
11
Session (PHP): server-side data storage persisting across multiple HTTP requests for the same user. session_start() initiates it. Cookie: key-value data stored in the CLIENT'S browser, sent with every request.
12
CRUD operations map to SQL: Create β†’ INSERT, Read β†’ SELECT, Update β†’ UPDATE, Delete β†’ DELETE. The backbone of any data-driven web application.
13
CMS (Content Management System): software that allows creating and managing web content without writing code (WordPress, Joomla, Drupal). Separates content from presentation.
3.5

Pure Virtual Functions and File Handling in C++

AItE0305
1
A virtual function in C++ is declared with the virtual keyword in a BASE class. When called through a base-class pointer/reference, it dispatches to the DERIVED class's version β€” not the base's.
2
This is RUNTIME polymorphism (dynamic dispatch): which function runs is decided at runtime based on the actual object type, not the pointer type.
3
Pure virtual function: declared with = 0 β€” virtual void draw() = 0;. It has NO body in the base class. Derived classes MUST provide an implementation or they too become abstract.
4
Abstract class: any class with at least one pure virtual function. It CANNOT be instantiated directly β€” it exists purely to define an interface (contract) that subclasses must fulfill.
5
Vtable (virtual table): the compiler creates a per-class table of function pointers. Each object carries a hidden vptr pointing to its class's vtable. This is the mechanism that makes dynamic dispatch work.
6
C++ file handling uses stream objects from <fstream>. Three classes: `ifstream` (input from file), `ofstream` (output to file), `fstream` (both input and output).
7
Opening a file: stream.open("filename", mode) or in constructor: ifstream fin("data.txt"). Check success with if (!fin) or fin.fail().
8
File modes (ios flags): ios::in (read), ios::out (write, truncates), ios::app (append), ios::trunc (truncate), ios::binary (binary mode). Combine with |: ios::in | ios::binary.
9
Text mode I/O: << and >> operators; getline(stream, str) for whole lines. Binary mode I/O: stream.write((char*)&obj, sizeof(obj)) and stream.read((char*)&obj, sizeof(obj)).
10
Always close files: stream.close(). This flushes the write buffer and releases the OS file handle. Streams also close automatically when they go out of scope (RAII).
11
Stream class hierarchy: ios (base) ← istream ← ifstream; ios ← ostream ← ofstream; istream + ostream β†’ iostream ← fstream.
12
Output formatting manipulators from <iomanip>: setw(n) (field width), setprecision(n) (decimal places), `fixed` (fixed-point), `left`/`right` (alignment), setfill(ch) (fill character).
3.6

Generic Programming and Exception Handling

AItE0306
1
Generic programming (templates) lets you write code ONCE that works for ANY data type. The type becomes a parameter: template <typename T>. The compiler generates type-specific versions at compile time.
2
Function template: a blueprint for a function. Example: template <typename T> T max(T a, T b) β€” one definition, works for int, double, string, etc.
3
Template functions can be overloaded β€” you can have multiple templates with the same name but different type-parameter counts. The compiler picks the best match.
4
Class template: a blueprint for an entire class. Example: template <typename T> class Stack ... β€” creates a type-safe Stack for any T.
5
STL (Standard Template Library): a ready-made toolkit of generic components. Three pillars: **Containers** (store and organize data), **Algorithms** (operations on data), **Iterators** (navigate through containers).
6
Common STL containers: vector (dynamic array), list (doubly linked list), map (key→value, sorted), unordered_map (hash map), set (unique sorted values), stack (LIFO), queue (FIFO).
7
STL algorithms work on any container via iterators: sort(), find(), binary_search(), reverse(), accumulate() β€” all from <algorithm>.
8
Exception handling: a clean way to separate error-handling code from normal logic. Keyword trio: `try` (wrap risky code), `throw` (signal an error), `catch` (handle the error).
9
When `throw` executes, normal execution stops and control unwinds the call stack until a matching catch is found. The thrown object carries error information.
10
Multiple catch blocks: you can have several catch blocks after one try, each handling a different exception type. They are checked in ORDER β€” put more specific types before more general ones.
11
catch(...) : catches ALL exception types β€” the safety net. Use it last after specific handlers.
12
Rethrowing: inside a catch block, bare throw; (no argument) re-throws the currently caught exception to the outer scope.
13
Standard exception hierarchy: all standard exceptions derive from std::exception. Common ones: std::runtime_error, std::logic_error, std::out_of_range, std::bad_alloc. Access .what() for the error message.
14
Uncaught exceptions: if no catch block handles a thrown exception, `std::terminate()` is called, ending the program.