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

Multiple choice technology security
  1. Heap Overflow

  2. Integer overflow

  3. Buffer overflow

  4. No Vulnerability

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The variables j and k are declared as unsigned char. Adding two unsigned char values together can yield a sum greater than 255. In C, this arithmetic wraps around due to modulo 256 behavior, resulting in an integer overflow vulnerability.

Multiple choice technology security
  1. Forcing buffer overflows

  2. Submitting random long strings to the application

  3. Causing underflow problems

  4. Including string specifiers in input data

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Format string vulnerabilities occur when user input is passed as the format argument to printf-style functions without proper validation. Attackers discover these flaws by embedding format specifiers like %x, %s, %n in their input and observing unexpected output or program behavior. If the application blindly uses the input as a format string, these specifiers leak memory contents or enable arbitrary writes. Buffer overflows (A) and underflows (C) are different vulnerability classes, while random long strings (B) might trigger crashes but won't specifically expose format string issues.

Multiple choice technology security
  1. Never rely on the operating system, database, or hardware to handle errors

  2. Your application’s code should always include its own error handler.

  3. All errors generated by internal components such as system calls, database queries, and other internal functions, should be handled by the application’s exception handler

  4. Never implement a generic error page

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

It is a security best practice to implement a generic error page to avoid revealing sensitive debugging details or stack traces to end users. The other statements correctly describe proper error-handling designs, making the recommendation to not implement a generic error page untrue.

Multiple choice technology security
  1. Safe APIs

  2. Banned APIs

  3. String APIs

  4. CAPIs

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Functions like strcpy, strcat, strncpy, sprintf (mistyped in prompt as sprint), and gets do not perform safe bounds-checking on buffers, making them highly vulnerable to buffer overflow attacks. Consequently, security standards and modern development guidelines classify them as banned APIs.

Multiple choice
  1. getchar() reads one character at a time till the user presses enter.

  2. putchar() prints one character on the screen at a time, read by the standard input.

  3. getch() reads alphanumeric character from the input device.

  4. getch() does not display the character input by it on the screen.

  5. All of the above

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

All the given options are correct.

Multiple choice
  1. Functions operate on actual address argument and return the address back to the calling function.

  2. The values of formal arguments passed by the calling function are received by the actual arguments of the called function.

  3. The detail of inner working of a function is known to the whole program.

  4. A class can always access the functions of another class with friend function.

  5. None of these

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

All of the options are false. So, this is correct option.

Multiple choice
  1. Array of bit fields are not permitted.

  2. Pointer cannot be used for addressing the bit fields directly.

  3. We can use only unsigned integer data type with bit fields.

  4. A bit field is set up with a structure declaration.

  5. All of the above

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

All  the options are true. So, this is the correct answer.

Multiple choice
  1. Strspn();

  2. Strnset();

  3. Strnsetu();

  4. Strdup();

  5. Strncpyl();

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This option is true because this function takes two arguments and it returns the position of the string from where the source array does not match with the target one. Format of this function is: Strspn( string 1, string 2); For example, suppose we enter first string as “good morning” and second string as “good luck”. So, the function will return 5 because after 5 characters, there is no match found in the strings.  

Multiple choice
  1. It saves disk space.

  2. Debugging (Removing the errors) is easy.

  3. Recursive calling is possible.

  4. Makes the program easier to understand.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Functions are programs that have names and perform a particular task. They are mostly used to perform a task again and again. They allow the users to reuse the same code without having to rewrite it. They are not considered to save disk space but they do save primary memory (RAM).

Multiple choice
  1. recursive function

  2. overloaded function

  3. inline function

  4. overridden function

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

A recursive function is a function that calls itself during execution. This allows the function to repeat itself several times displaying the result after each iteration. Recursive functions are popular among programmers since they allow them to write efficient program using minmal amount of code. 

Multiple choice
  1. virtual void print()=0;

  2. virtual void print=0 ()

  3. virtual void print()={0}

  4. virtual void print()=(0)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

A pure virtual function is a function that has no body in the base class. To declare a function as virtual we just have to add 'function() = 0' in the function declaration. A class that contains at least one pure virtual function is called an 'abstract' class and it cannot be instantiated.

Multiple choice
  1. try

  2. else

  3. catch

  4. if

  5. finally

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

The finally block contains the code that we want to run irrespective of whether the try block contains an exception or not. If the try block has an exception the control will move from the try block to the catch block and then to the finally block. If there is no exception the control will move directly from the try block to the finally block.

Multiple choice
  1. The null data type has only one value.

  2. The typeOf operator shows null as boolean values.

  3. null is not same as 0

  4. null is a keyword

  5. Value of a variable can be set as null.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The typeof operator in JavaScript identifies null values as being of type Object, not of type boolean.