Computer Knowledge
Programming Fundamentals
2,611 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
B
Correct answer
Explanation
Data types define the kind of values a variable can hold (int, void for return type, Button as a class type). 'public' is an access modifier keyword that controls visibility, not a data type. Access modifiers and data types are different categories in Java.
B
Correct answer
Explanation
In C, malloc returns a void* pointer which is automatically converted to any other pointer type without explicit casting. Adding a cast is unnecessary and can actually hide errors if you forget to include stdlib.h. Modern C style recommends avoiding the cast. Option A is incorrect - casting is not required.
-
getchar();
-
getche();
-
ungetc();
-
getch();
B,D
Correct answer
Explanation
getche() and getch() are non-standard functions (common in Turbo C/C++ and Windows conio.h) that read characters with and without echo respectively. They are not part of the ANSI C standard library. getchar() and ungetc() are standard ANSI functions defined in stdio.h. Therefore options B and D are correct as the non-standard functions.
-
null pointer
-
wild pointer
-
Dangling pointer
-
None of the above
C
Correct answer
Explanation
Calling free() deallocates the memory block but does not modify the pointer itself. The pointer continues pointing to the deallocated memory, making it a dangling pointer. A null pointer must be explicitly assigned, and a wild pointer is one that is uninitialized.
-
Pointer to an array of 10 integers.
-
A pointer to function returning an array of 10 integers.
-
Array of 10 function pointers returning int
-
Array of 10 integer pointers.
A
Correct answer
Explanation
The declaration int (*a)[10] declares 'a' as a pointer to an array of 10 integers. The parentheses around (*a) are crucial - they make 'a' a pointer first, which then points to an array of 10 ints. Without parentheses, it would be an array of 10 pointers (int *a[10]). Option B incorrectly suggests a function pointer, option C describes int (*a[10])(), and option D describes int *a[10].
B
Correct answer
Explanation
In C, you cannot directly compare two structures using the == operator - it will cause a compilation error. Structures must be compared member by member, or using memcmp() for simple structures without padding. Option A (True) is incorrect because == doesn't work on structures.
B
Correct answer
Explanation
In C, you cannot directly compare two structures using the == operator - it will cause a compilation error. Structures must be compared member by member, or using memcmp() for simple structures without padding. Option A (True) is incorrect because == doesn't work on structures. Note: This is a duplicate of question 155591.
-
General: Log
-
General: Run Logic
-
General: Miscellaneous
-
General: Additional Attributes
A
Correct answer
Explanation
The General: Log category in LoadRunner's run-time settings allows developers to configure logging behavior, including the option to send messages only when an error occurs. Meanwhile, Run Logic defines the execution flow, and Miscellaneous governs error handling and threads.
A
Correct answer
Explanation
Java uses curly braces { } to group multiple statements into code blocks. This is essential for control structures like if, for, while, and for defining class and method bodies. Blocks create a new scope for local variables and are a fundamental part of Java syntax.
C
Correct answer
Explanation
Java supports three types of comments: single-line comments using //, multi-line comments using /* /, and Javadoc documentation comments using /* */. Each serves different purposes in code documentation.
-
Functions
-
Templates
-
Function pointers
-
Pointer of pointers
C
Correct answer
Explanation
In C++, delegates are not built-in language constructs, but their conceptual equivalent is a function pointer (or std::function/functors), which stores a reference to a function to be called dynamically. Templates are compile-time code generators, and functions are direct invocations.
-
strcat(str1,str2)
-
str1.Append(str2)
-
str1.CopyAtEnd(str2)
-
str1=str1+str2
D
Correct answer
Explanation
In C#, string concatenation is done using the + operator, so str1=str1+str2 appends str2 to str1. Unlike C's strcat() function, C# uses overloaded operators for string manipulation.
-
Pointers are not supported in C#
-
Pointers are supported in C# as is in C++
-
Pointers are replaced by delegates
-
Pointers can be used by declaring unsafe blocks
D
Correct answer
Explanation
C# does support pointers, but only within explicitly marked unsafe code blocks. This provides controlled access to pointer functionality while maintaining type safety by default, unlike C++ where pointers are freely available.
-
PARA A
-
PARA B
-
PARA C
-
PARA D
B
Correct answer
Explanation
The COBOL GOTO statement with DEPENDING ON uses 1-based indexing: GOTO A,B,C,D DEPENDING ON X transfers control to the first label when X=1, second label when X=2, third when X=3, fourth when X=4. When X=2, control transfers to PARA B. This is a computed GOTO based on the ordinal position of the labels.
-
catch,finally
-
finally
-
catch
-
catch,catch,finally
A,B,D
Correct answer
Explanation
In Java, a try block must be followed by either a catch block, a finally block, or both. The options correctly identify valid combinations like try-catch-finally, try-finally, and multiple catches. However, the option "catch" is marked false when a single catch block is also syntactically valid in Java. Since 'catch' is marked false, the stored answers are partially inconsistent, but try-catch-finally and try-finally are indeed correct.