Karnataka II PUC Computer Science (KSEAB) common mistakes
Karnataka II PUC Computer Science (KSEAB) · Understand the traps and how to avoid them.
Writes the 2's complement of a negative number by inverting all bits and stopping there, so −5 in 8 bits becomes 11111010 instead of 11111011, and gives the 1's-complement range as −128 to +127 for signed 8-bit numbers.
The inversion step feels like a finished operation, and the final +1 is easy to drop when the low bit is 0 and the carry has to ripple across several positions. Range questions get answered from memory of 'one less at the negative end' without re-deriving from 2^n.
What to do instead
Do the arithmetic check every time: magnitude + 2's complement must equal 2^n with the carry discarded (5 + 251 = 256). Practise three cases - low bit 1, low bit 0, and all-ones - so carry propagation is drilled. Re-derive signed range as −2^(n−1) to +2^(n−1) − 1 from the bit pattern, not by recall.
Draws a decision in a flowchart using a rectangle or parallelogram, puts input in an oval, and writes 'pseudocode' containing C++ tokens such as cin>>, cout<<, int i; and braces.
Symbols are memorised as a set of shapes without linking each shape to the one decision it represents, and pseudocode is confused with code because worked examples in the textbook use C++-like lines.
What to do instead
Anchor four shapes to four verbs: oval = start/stop, parallelogram = input/output, rectangle = process, diamond = decision; connectors are small circles. For pseudocode use English keywords only (READ, PRINT, IF ... ENDIF, WHILE ... ENDWHILE, SET) and keep declarations out. Convert one given algorithm into a flowchart and back, checking that no C++ token survives.
Predicts the output of expressions like 7/2*2.0, 10%3, or a++ + ++a by evaluating 'as a calculator', and writes if (marks = 0) when the question asks for an equality test.
Integer division, truncation toward zero and left-to-right evaluation of equal-precedence operators are not internalised, so the mental model of real-number arithmetic is applied. Assignment and comparison look almost identical at a glance under exam pressure.
What to do instead
Keep a precedence ladder (unary, then * / %, then + −, then relational, then == !=, then &&, then ||) and evaluate one operator at a time on paper, writing the partially reduced expression after each step. For equality, train the habit of writing the constant first (0 == marks) so an accidental assignment becomes a compile error you would catch.
Declares int a[5]; then writes a loop for(i=1;i<=5;i++) to read five elements into a[i], leaving a[0] as garbage and writing one value past the end of the array; similarly reports the last valid index of a 10-element array as 10.
Everyday counting starts at 1, and the declaration size is remembered as the largest index. Loop bounds are copied from one example to the next without re-checking against the declared size.
What to do instead
Use one template for every array loop - for(i=0;i<n;i++) - and state aloud 'size n means indices 0 to n−1'. When tracing, draw the boxes first and label them 0..n−1 above the row so an out-of-range subscript is visible before the code is written.
Writes void swap(int a,int b) for a question that requires the caller's variables to change, then claims in the trace that the values in main were exchanged.
Call by value and call by reference differ by a single ampersand in the parameter list, while the copy semantics are abstract and invisible on the page, so the two versions look interchangeable.
What to do instead
Draw two memory columns for every function call - one for the caller, one for the callee - and mark each parameter as 'copy' or 'alias'. Apply the rule: no & in the parameter means the callee works on a copy, so changes vanish on return; use int &a only when the caller's variable must be modified. Write both versions of swap and compare their actual outputs.
Defines member functions outside the class without the ClassName:: qualifier, gives a constructor a return type such as void, and omits the semicolon after the closing brace of the class definition.
The class body looks like an ordinary block, so the terminator feels unnecessary; and because a constructor resembles a function, a return type seems required. Scope resolution is the easiest token to forget when moving code out of the class.
What to do instead
Reproduce one fixed skeleton from memory before every class question - class X { public: X(); void show(); }; then X::X(){ } and void X::show(){ } - and run a three-point check: no return type on the constructor, ClassName:: on every out-of-class definition, and a semicolon after the class brace.
States that private members of a base class are not inherited by the derived class, and writes the order of execution in a derived-object program as derived constructor first, then base constructor.
'Private members cannot be accessed' is over-generalised into 'not inherited', and construction order is guessed from the order in which classes appear in the source file rather than from the object's build sequence.
What to do instead
Use the precise sentence: private members are inherited but not directly accessible in the derived class; access is only through base-class public or protected functions. For order, remember the object is built from the inside out - base constructor, then derived constructor, and destruction in the reverse order - and verify by printing messages from each constructor in a small traced program.
Reads a file with while(!fin.eof()){ fin.getline(line,80); cout<<line; } and the final record is printed twice; also opens a file for writing without checking whether the open succeeded.
eof() becomes true only after a read has already attempted to move past the end, so the loop body executes one extra time with the previous buffer contents still in place. The open call is treated as an infallible statement rather than an operation that can fail.
What to do instead
Test the read itself, because it returns the stream and the stream converts to false on failure: while(fin.getline(line,80)) or while(fin>>x). After every open, check with if(!fin) or fin.fail() and report the error before using the stream. Remember to close the file after the loop.
Answers 'remove the marks column' with DELETE FROM student WHERE marks<30, and writes SELECT * FROM student WHERE marks = NULL to list students whose marks are missing.
DDL and DML are learned as definitions to reproduce rather than as commands chosen by intent, and NULL is treated as an ordinary value that can be compared with = instead of as an unknown.
What to do instead
Choose the command from the intent: rows go with DELETE, column or table structure with ALTER TABLE ... DROP COLUMN or DROP TABLE, all rows with DELETE without WHERE. For NULL, remember that any comparison with = NULL yields unknown, so only IS NULL and IS NOT NULL can test it; verify by writing both and noting which returns rows.
Uses <ol> for a bulleted list and <ul> for a numbered list in the same answer paper, closes a line break with </br>, and places <tr> outside the <table> element or puts <td> directly inside <table>.
Tags are memorised as pairs of letters rather than by the meaning of the words (ordered/unordered), and container hierarchy is skipped because the browser tolerates sloppy nesting, so the error never shows up in practice.
What to do instead
Tie each tag to its word: ol = ordered = numbered, ul = unordered = bullets; li is the item in both. Learn that br and hr are empty elements with no closing tag. For tables, indent the nesting table > tr > th/td and check every opening tag has a matching close in the reverse order before moving on.