Computer Knowledge

Programming Output Evaluation

1,953 Questions

Programming output evaluation tests the ability to trace code execution in languages like C, Java, and SAS. It focuses on arrays, loops, pointers, and data type conversions. These technical questions are standard in computer knowledge sections for IT officer and bank exams.

Java string bufferC language pointersLoop execution outputsData type conversionsMacro variable evaluation

Programming Output Evaluation Questions

Multiple choice technology security
  1. Buffer overflow

  2. Off by one error

  3. Format string vulnerability

  4. No vulnerabilities are present in this code

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

The code directly prints argv[1] as the format string to printf. Since argv[1] comes from the command line (user input), an attacker can supply format specifiers like %x to read stack data or %n to write arbitrary values. This allows reading memory contents and potentially executing arbitrary code. Always use printf(%s, argv[1]) instead.

Multiple choice technology security
  1. Integer overflow

  2. Buffer overflow

  3. Stack overflow

  4. Data type mismatch

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

Adding two unsigned integers can cause integer overflow if the sum exceeds UINT_MAX (typically 2^32 - 1). The result wraps around modulo 2^32, producing an unexpectedly small value. This can lead to security issues like buffer allocation errors or logic bypasses. For example, if userinput1 = 4000000000 and userinput2 = 4000000000, total wraps to ~1.7 billion instead of the expected ~8 billion.

Multiple choice technology security
  1. SQL Injection

  2. Arc Injection

  3. Buffer Overflow

  4. both 2 and 3

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

The code exhibits a classic buffer overflow vulnerability through its file handling approach. The variable 'x' is declared as char instead of int, which cannot properly represent EOF (-1). This causes an infinite loop because fgetc() returns EOF as an int, but storing it in a char truncates the value, preventing proper loop termination. Additionally, the lack of input validation on file sizes means the code blindly copies content without bounds checking. SQL Injection (A) and Arc Injection (B) are unrelated to this memory corruption issue.

Multiple choice technology security
  1. 1

  2. 2

  3. Both

  4. None

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

Line 2 (gets(ipstring)) creates a buffer overflow because gets() reads input until newline without checking buffer size. Since ipstring is only 80 characters, any input longer than 79 characters will overflow the buffer, corrupting memory. Line 1 (getchar()) is safe as it reads a single character. The gets() function is inherently unsafe and has been deprecated precisely because it cannot prevent buffer overflows - it doesn't take a buffer size parameter.

Multiple choice technology security
  1. Heap overflow

  2. Integer overflow

  3. Off by one error

  4. None of the above

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

The loop condition is i < 3 but i starts at 0 and is incremented before the array write: i++ makes i=1 in the first iteration (writing to k[1]), then i=2 (k[2]), and i=3 (k[3]). Since k has size 3, writing to index 3 is an off-by-one out-of-bounds write.

Multiple choice technology security
  1. Static Code Analysis is the analysis of software code by actually executing the binaries resulting from this code

  2. Static Code Analysis is the analysis of software code without actually executing the binaries resulting from this code

  3. Static Code Analysis is the analysis of executables resulting from this code

  4. None of the above

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

Static code analysis examines source code for defects, security vulnerabilities, and coding standard violations without executing the program. This is distinct from dynamic analysis, which requires running the application. Static analysis tools parse code, build abstract syntax trees, and apply rules to identify potential issues at compile time.

Multiple choice
  1. 5

  2. 15

  3. 10

  4. 25

  5. Compilation Error

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

Functions are another type of variable in JavaScript. Creating a function within another function changes the scope of the function in the same way it would change the scope of a variable.The functions defined within another function won't be accessible outside the function unless they have been attached to an object that is accessible outside the function. In the above code, we are calling the function named 'fun3()' , which in turn is calling another function named 'fun1()' with two arguments (5) and (5). The fun1() will copy the value of the first 5 to i and the second value will be copied to j. The result of fun2() will be sent to 'fun1()'. fun1() will return the result (25) to fun3(). The result will be copied to the variable 'r' and printed using an alert box.

Multiple choice
  1. Compilation Error

  2. This,is,a,sample,string

  3. This,is,a,sample,string,

  4. ,This,is,a,sample,string,

  5. T,h,i,s,i,s,a,s,a,m,p,l,e,s,t,r,i,n,g

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

The split() method is used to split a string into an array of substrings, and returns the new array. In the above code, the spaces of the string will be converted to commas (,)

Multiple choice
  1. Compilation Error.

  2. The word 'Hello' will be printed infinitely.

  3. 'Hello' will be printed only once.

  4. 'Hello' will not be printed at all.

  5. 'Hello' will print once and then program will show a runtime error.

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

The C for statement has the following form:

for(start;condition;increment/decrement)   {}

In the statement given above since, nothing has been specified the for loop, it  will run infinitely. To terminate such a loop the 'ctrl+break' key combination should be pressed.
Multiple choice
  1. Collection of values having same data type

  2. The basic element recognized by the compiler

  3. The largest individual units of program

  4. Pointers

  5. References

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

Tokens are individual words and punctuation marks in passage of text. In C, program the smallest individual units are known as C Tokens. C has Six types of Tokens - Keywords,  Strings, Identifiers, Operators, Constants and special symbols.

Multiple choice
  1. Prints the error message specified by the compiler.

  2. Works same as printf().

  3. Prints the garbage value assigned by the compiler.

  4. Works same as the gets() method.

  5. None of the above

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

The C library function void perror(const char *str) prints a descriptive error message to stderr. First the string str is printed followed by a colon then a space. Syntax : void perror (const char *str) where str is the user defined message that prints before the actual error message.

Multiple choice
  1. 20

  2. 21

  3. 18

  4. 19

  5. 22

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

The ++ operator is the pre fix increment operator. The pre increment operator first increments the variable up to break point then starts assigning the final value to all variable. Therefore the statement x=++i + ++i + ++i; will translate into x=5+6+7; after all the increments are finished, x will have the value 7 since, that is the last value after the statement. Now the final result will be x=7+7+7 that is 21.