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

Multiple choice technology programming languages
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. getchar();

  2. getche();

  3. ungetc();

  4. getch();

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. null pointer

  2. wild pointer

  3. Dangling pointer

  4. None of the above

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Pointer to an array of 10 integers.

  2. A pointer to function returning an array of 10 integers.

  3. Array of 10 function pointers returning int

  4. Array of 10 integer pointers.

Reveal answer Fill a bubble to check yourself
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].

Multiple choice technology programming languages
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Functions

  2. Templates

  3. Function pointers

  4. Pointer of pointers

Reveal answer Fill a bubble to check yourself
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.

Multiple choice technology programming languages
  1. Pointers are not supported in C#

  2. Pointers are supported in C# as is in C++

  3. Pointers are replaced by delegates

  4. Pointers can be used by declaring unsafe blocks

Reveal answer Fill a bubble to check yourself
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.