Aspirant Academy

MCQ

Paper - II (iv) — Programming Fundamentals MCQ - Practice Questions with Answers

Solve 45 Paper - II (iv) — Programming Fundamentals questions for RAS/RPSC preparation.

Practice questions

Q1In a basic blockchain, why does changing data in an earlier block become tamper-evident?

A Every block is automatically encrypted with the same password.
B A block includes a hash-based identifier of the previous block, so changing earlier data changes later linkage checks.
C Blocks are stored only on a single central server that blocks all edits.
D Each block contains the private key of every later block.
Explanation

Blockchain records are grouped into blocks that are linked using hash-based identifiers of earlier block data. If data in an older block is altered, its identifier changes, and later blocks that refer to the old value reveal the inconsistency.

Q2In C, what is the value printed by printf("%d", 3 + 4 * 2 == 11 && 0 || 5); assuming the usual integer result of relational and logical operators?

A 1
B 0
C 11
D 5
Explanation

C operator precedence places multiplication above addition, equality below addition, logical AND below equality, and logical OR below logical AND. Thus 3 + 4 * 2 becomes 11, 11 == 11 becomes 1, 1 && 0 becomes 0, and 0 || 5 becomes 1.

Q3Which feature of a blockchain most directly helps detect tampering with an earlier block?

A Each block is stored only on one central server.
B Every transaction is deleted after the next block is created.
C Blocks are renamed alphabetically after validation.
D Each block includes a cryptographic hash link to the previous block's contents.
Explanation

A blockchain connects blocks by storing hash-based references to earlier block data. If an old block is altered, its computed hash changes, so the following block's stored reference no longer matches and the alteration becomes detectable.

Q4A C program declares union Data { int i; float f; char text[20]; }; Which statement is the best reason a union is different from a structure here?

A All union members are initialized automatically whenever the union variable is created.
B The union always occupies storage equal to the sum of all members, just like a structure.
C A union member can be accessed only through a pointer, while a structure member can use the dot operator.
D The members share the same storage area, so writing one member affects the stored representation used by the others.
Explanation

A C structure allocates separate storage for each member, but a union overlays its members in a common storage area large enough for its largest member with required alignment. Therefore it is suitable when exactly one representation is intended to be active at a time.

Q5In C, let `int a[3] = {2, 4, 6}; int *p = a;`. Which expression evaluates to `4` without changing `p`?

A `p[2]`
B `*p + 1`
C `*(p++)`
D `*(p + 1)`
Explanation

In C array expressions commonly provide a pointer to the first element, and pointer arithmetic is scaled by the pointed type. Therefore `p + 1` points to `a[1]`, and `*(p + 1)` reads `4` while leaving `p` unchanged.

You've seen 5 of 45 sample questions

Unlimited practice on Paper - II (iv) — Programming Fundamentals comes with the RAS Test Series + Practice pack or Gate Pass.

More questions

6In C, what is the value of x after executing: int x = 2 + 3 * 4;

A20
B24
C14
D9

7Which statement correctly matches one machine-learning idea with one blockchain idea?

ASupervised learning trains only on unlabeled data, and a blockchain normally stores data in one central private database.
BUnsupervised learning requires every record to have a target label, and a blockchain block cannot include a cryptographic hash.
CSupervised learning uses labeled examples to learn input-output relationships, and a blockchain links tamper-evident ledger records using cryptographic techniques.
DReinforcement learning is the same as file handling, and blockchain consensus is another name for operator precedence.

8For a local variable declared inside a C function block, which statement about its scope is correct?

AIt is visible throughout the entire source file after compilation.
BIt is visible only inside functions that are called by the declaring function.
CIt is visible in every block that has a variable with the same name.
DIt is visible from its declaration point until the end of the enclosing block, subject to nested-block hiding.

9In C#, which pairing correctly classifies the user-defined types struct Point { public int X; public int Y; } and enum Mode { Read, Write }?

Astruct Point is a value type, while enum Mode is a reference type.
BBoth struct Point and enum Mode are value types.
Cstruct Point is a reference type, while enum Mode is a value type.
DBoth struct Point and enum Mode are reference types.

10A Python script is run as python report.py data.csv out.txt. Which statement about sys.argv and file handling is correct?

Asys.argv contains only data.csv and out.txt, while report.py is excluded from the list.
Bopen() converts command-line arguments into file objects automatically when their names end in .txt or .csv.
Csys.argv[0] refers to report.py, sys.argv[1] is data.csv, and using with open(...) closes the file when the block exits.
Dsys.argv[0] is data.csv, and open() automatically closes a file only when write mode is used.

11A C function is declared as void update(int a[]) { a[0] = 99; }. If int arr[3] = {1, 2, 3}; is passed as update(arr);, what is arr[0] after the call?

A1
B99
CThe program is invalid because arrays cannot be passed to functions
D0

12For a Python program run as `python report.py alpha beta`, which statement about command line arguments is correct?

A`sys.argv[0]` is `alpha`, because user arguments start at index 0.
B`sys.argv[0]` is the script name, while `alpha` and `beta` are later elements.
CPython command line arguments are available only through environment variables.
D`sys.argv` excludes the script name and contains only `alpha` and `beta`.

13In C, what is the value of `TUE` in the declaration `enum Day { MON = 1, TUE, WED = 5, THU };`?

A1
B2
C6
D5

14In Python, what is the main purpose of using an `if ... elif ... else` chain instead of three independent `if` statements for mutually exclusive conditions?

AIt converts all tested values to strings before comparison.
BIt selects only the first true branch among the alternatives.
CIt is required only when a loop is present.
DIt makes every condition execute once before choosing a result.

15In Java, which statement about variable initialization is correct?

AInstance fields receive default values, but a local variable must be definitely assigned before use.
BOnly local variables receive default values; fields must always be explicitly initialized.
CBoth fields and local variables are always initialized to zero or null automatically.
DJava permits reading any uninitialized variable and assigns the value at run time.

More topics in Programming & Data Structures (Senior CI)

Explore other subjects