Computer Knowledge
Programming Fundamentals
2,381 Questions
Programming fundamentals form the core logic of software development and computer science. This includes variable declarations, pointer assignments, loop iterations, and exception handling. These technical topics are regularly tested in computer knowledge and IT officer competitive examinations.
Variables and arraysPointer assignmentsLoop iterationsException handling blocksCompile time errorsFunction references
Programming Fundamentals Questions
-
Underflow
-
Overflow
-
Top
-
Push
-
Pop
B
Correct answer
Explanation
This condition is checked into the stack before performing the 'insertion' operation.
-
Underflow
-
Overflow
-
Top
-
Push
-
Pop
B
Correct answer
Explanation
This condition must be verified before inserting a new element into the stack.
-
float, int pointer
-
float pointer, int pointer
-
float, int
-
float pointer, int
C
Correct answer
Explanation
The macro floatptr expands to 'float *', so 'floatptr f1,f2' becomes 'float *f1,f2'. This declares f1 as a pointer to float, but f2 as a regular float (the * only binds to f1). Similarly, 'intptr p1,p2' becomes 'int *p1,p2', making p2 a regular int. This is a classic macro pitfall.
-
It will work correctly since the for loop covers the entire list.
-
It may fail since each node “nptr” is freed before its next address can be accessed.
-
This is invalid syntax for freeing memory.
-
The loop will never end.
B
Correct answer
Explanation
The loop frees nptr BEFORE reading nptr->next in the next iteration. After free(nptr), accessing nptr->next is undefined behavior - the memory has been deallocated. The correct approach is to save nptr->next BEFORE freeing nptr: next = nptr->next; free(nptr); nptr = next;
-
static
-
extern
-
register
-
function argument
-
Plus
-
Compilation Error
-
Runtime Error
-
Linker Error
B
Correct answer
Explanation
The macro big(a,b) returns the larger value, so big(3,5) returns 5. The condition (3+5)>5 evaluates to true (8>5). When swap(a,b) expands, it executes temp=a; a=b; b=temp; making a=5 and b=3. The printf outputs "5 3". The key point is that the swap macro lacks braces, but it still executes sequentially.
-
Breaks out of the if statement
-
Exits the function
-
Compiler error
-
Nothing
C
Correct answer
Explanation
The break statement can only be used inside loops (for, while, do-while) or switch statements. Using break inside an if statement that is not inside a loop or switch causes a compilation error. The compiler will reject this code because break has no valid target to break out of.
-
float, int pointer
-
float pointer, int pointer
-
float, int
-
float pointer, int
A
Correct answer
Explanation
The macro floatptr expands to float , so floatptr f1,f2 becomes float *f1,f2. Due to precedence, this declares f1 as float but f2 as float (only f1 gets the asterisk). For intptr (defined as int ), intptr p1,p2 becomes int *p1,p2, declaring p1 as int and p2 as int. Therefore f2 is float and p2 is int.
-
only from the innermost loop
-
only from the innermost switch
-
from all loops and switches
-
from the innermost loop or switch
D
Correct answer
Explanation
The break statement in C++ exits from the innermost loop or switch statement that contains it. It does not exit from all nested loops or switches simultaneously - only the immediately enclosing one. To exit from multiple levels, you would need multiple break statements or a different control structure like goto.
-
stdio.h
-
math.h
-
ctype.h
-
string.h
C
Correct answer
Explanation
The toascii() function is a character-handling function used to convert integer values into standard ASCII character range. It is declared in the standard library header file ctype.h in C and C++. Other headers like stdio.h or math.h handle input/output or mathematical operations respectively.
B
Correct answer
Explanation
cin is the standard input stream object in C++ that is used to input data from the keyboard. It is part of the iostream library and is used with the extraction operator (>>) to read values into variables. cout is for output, cerr is for error output, and get is a specific method.
-
sequential
-
count
-
repetitive
-
incremental
C
Correct answer
Explanation
A while loop in C++ is a control structure that repeatedly executes a block of code as long as a specified condition remains true. Because it involves repeating instructions, it is classified as a repetitive control structure.
-
Missing parentheses in return statement.
-
The function should be defined as int f(int a, int b).
-
Redeclaration of 'a'.
-
None of the above
C
Correct answer
Explanation
The function has a parameter named 'a', and then inside the function body, 'a' is redeclared as a local variable with 'int a;'. This creates a redeclaration error because you cannot declare a variable with the same name as a parameter in the same scope. Option C correctly identifies this as 'Redeclaration of a'. The parameter 'a' is already declared in the function signature, so declaring it again inside is a compilation error.