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
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.
A
Correct answer
Explanation
The print() method writes text to the output stream without appending a newline, unlike println() which automatically appends a newline at the end of the printed content.
A
Correct answer
Explanation
Java literals are source code representations of fixed values. For example, 100 is an integer literal, 3.14 is a floating-point literal, and 'x' is a char literal. These literal representations directly create constant values in the code without needing variables.
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.
A
Correct answer
Explanation
This is the correct basic for loop syntax in Java. The initialization runs once, the condition is checked before each iteration, and the iteration statement executes after each loop cycle.
-
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.