C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.
C is the most widely used computer language.
It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.
Q) What is the output of the following code statements? The compiler saves the first integer at the memory location 4062. Integer is one byte long.
integer a
pointer b
a = 20
b = &a
print *b
Op 1: 4062 Op 2: 4063 Op 3: 20 Op 4: 10
Correct Op : 3
Q) What is the output of the following code statements? The compiler saves the first integer at the memory location 4165 and the rest at consecutive memory spaces in order of declaration. Integer is one byte long.
integer a, b
pointer c, d
a = 30
c = &a
b = *c
a = a + 10
print b
Op 1: 30 Op 2: 4165 Op 3: 40 Op 4: 4166
Correct Op : 1
Q) What is the output of the following code statements? The compiler saves the first integer at the memory location 4165 and the rest at consecutive memory spaces in order of declaration. Integer is one byte long.
integer a
pointer c, d
a = 30
c = &a
d = c
a = a + 10
print *c
Op 1: 30 Op 2: 4165 Op 3: 40 Op 4: 4166
Correct Op : 3
Time & Space Complexity:
Q) The memory space needed by an algorithm has a fixed part independent of the problem instance solved and a variable part which changes according to the problem instance solved. In general, which of these two is of prime concern to an algorithm designer?
Op 1: Fixed part Op 2: Variable Part
Op 3: Product of fixed part and variable part Op 4: None of these
Correct Op : 2
Q) While calculating time complexity of an algorithm, the designer concerns himself/herself primarily with the run time and not the compile time. Why?
Op 1: Run time is always more than compile time.
Op 2: Compile time is always more than run time.
Op 3: Compile time is a function of run time.
Op 4: A program needs to be compiled once but can be run several times.
Correct Op : 4
Q) Pankaj and Mythili were both asked to write the code to evaluate the following expression:
a - b + c/(a-b) + (a-b)2
Pankaj writes the following code statements (Code A):
print (a-b) + c/(a-b) + (a-b)*(a-b)
Mythili writes the following code statements (Code B):
d = (a-b)
print d + c/d + d*d
If the time taken to load a value in a variable, for addition, multiplication or division between two operands is same, which of the following is true?
Op 1: Code A uses lesser memory and is slower than Code B
Op 2: Code A uses lesser memory and is faster than Code B
Op 3: Code A uses more memory and is faster than Code B
Op 4: Code A uses more memory and is slower than Code B
Correct Op : 1
Q) Vrinda writes an efficient program to sum two square diagonal matrices (matrices with elements only on diagonal). The size of each matrix is nXn. What is the time complexity of Vrinda's algorithm?
Op 1: &theta(n^2) Op 2: &theta(n)
Op 3: &theta(n*log(n)) Op 4: None of these
Correct Op : 2
Q) Tarang writes an efficient program to add two upper triangular 10X10 matrices (elements on diagonal retained). How many total additions will his program make?
Op 1: 100 Op 2: 55 Op 3: 25 Op 4: 10
Correct Op : 2
Q) Ravi and Rupali are asked to write a program to sum the rows of a 2X2 matrices stored in the array A.
Ravi writes the following code (Code A):
for n = 0 to 1
sumRow1[n] = A[n][1] + A[n][2]
end
Rupali writes the following code (Code B):
sumRow1[0] = A[0][1] + A[0][2]
sumRow1[1] = A[1][1] + A[1][2]
Comment upon these codes (Assume no loop-unrolling done by compiler):
Op 1: Code A will execute faster than Code B.
Op 2: Code B will execute faster than Code A
Op 3: Code A is logically incorrect.
Op 4: Code B is logically incorrect.
Correct Op : 2
Q) There is an array of size n initialized with 0. Akanksha has to write a code which inserts the value 3k at position 3k in the array, where k=0,1…(till possible). Akanksha writes an efficient code to do so. What is the time complexity of her code?
Op 1: &theta(n^2) Op 2: &theta(n)
Op 3: &theta(log3(n)) Op 4: &theta(3n)
Correct Op : 3
Q) There are two matrices A and B of size nXn. The data in both these matrices resides only at positions where both the indices are a perfect square. Rest all positions have 0 as the data. Manuj has available a third matrix initialized with 0's at all positions. He writes an efficient code to put the sum of A and B in C. What is the time complexity of Manuj's program?
Op 1: &theta(n^2) Op 2: &theta(n)
Op 3: &theta(n1/2) Op 4: &theta(log(n))
Correct Op : 2
Q) Ravi has to add an strictly upper triangular (no elements at diagonal) and a strictly lower triangular square matrix (no elements at diagonal) and put the result in a third matrix. What is the time complexity of Ravi's algorithm? Assume that storing a value in a memory space takes negligible time, while each addition between values takes the dominating amount of time.
Op 1: &theta(n^2) Op 2: &theta(n)
Op 3: &theta(1) Op 4: None of these
Correct Op : 3
Q) We have two 100X3 (rowsXcolumn) matrices containing mid-term exam marks and end-term exam marks of 100 students. Each row refers to a particular student, while columns refer to marks in English, Social Sciences and Maths. The end-term and mid-term marks of each student in each subject have to be added to get his total score in each subject, to be put in a third matrix (100X3). Parinidhi writes a code (Code A), where the outer loop iterates over the rows, while the inner loop iterates over the columns. Shashi writes a code (Code B), where the outer loop iterates over the columns, while the inner loop iterates over rows. Which of the following is true with regard to their code ignoring any caching or memory storage effects?
Op 1: Code A is faster than Code B
Op 2: Code B is faster than Code A
Op 3: Code A and Code B will run in the same amount of time
Op 4: The comparison between the speed of the codes cannot be made.
Correct Op : 2
Q) A code takes the following code steps (equivalently time unit) to execute: 5*n3 + 6*n2 + 1. Which of the following is not true about the time complexity of the program?
Op 1: It has a time complexity of O(n3)
Op 2: It has a time complexity of O(n4)
Op 3: It has a time complexity of O(n2)
Op 4: It has a time complexity of &theta(n3)
Correct Op : 3
Q) We have two programs. We know that the first has a time complexity O(n2), while the second has a complexity &omega(n2). For sufficiently large n, which of the following cannot be true?
Op 1: Both codes have same complexity
Op 2: The first code has higher time complexity than the second
Op 3: The second code has lower time complexity than the first code.
Op 4: Both codes are the same.
Correct Op : 2
Q) The time complexity of code A is &theta(n), while for Code B it is &theta(log(n)). Which of the following is true for sufficiently large n?
Op 1: Both code have the same time complexity
Op 2: Code A has higher time complexity
Op 3: Code B has higher time complexity
Op 4: No comparison can be made between the time complexity of the two codes.
Correct Op : 2
Q) Rajini is given an efficient code for summing two nXn matrices and putting the result in a third matrix. She is asked to find it's time complexity. She realizes that the number of iterations required is more than n. What can she claim with regard to the complexity of the code?
Op 1: It is O(n) Op 2: It is O(n2)
Op 3: It is &theta(n) Op 4: It is &omega(n)
Correct Op : 4
Q) Gautam is given two codes, A and B, to solve a problem, which have complexity &theta(n) and &theta(n2) respectively. His client wants to solve a problem of size k, which Gautam does not know. Which code will Gautam deliver to the client, so that the execution is faster?
Op 1: Code A Op 2: Code B
Op 3: Gautam cannot determine Op 4: Both codes have the same execution time, so deliver any.
Correct Op : 3
Q) Surbhi is given two codes, A and B, to solve a problem, which have complexity O(n3) and &omega(n4) respectively. Her client wants to solve a problem of size k, which is sufficiently large. Which code will Surbhi deliver to the client, so that the execution is faster?
Op 1: Code A Op 2: Code B
Op 3: Surbhi cannot determine Op 4: Both codes have the same execution time, so deliver any.
Correct Op : 1
Q) Vibhu is given two codes, A and B, to solve a problem, which have complexity O(n4) and &omega(n3) respectively. Her client wants to solve a problem of size k, which is sufficiently large. Which code will Gautam deliver to the client, so that the execution is faster?
Op 1:Code A Op 2:Code B
Op 3:Vibhu cannot determine Op4:Both codes have the same execution time, so deliver any.
Correct Op : 3
Q) Pavithra is given two codes, A and B, to solve a problem, which have complexity &theta(n3) and &omega(n3) respectively. Her client wants to solve a problem of size k, which is sufficiently large. Which code should she deliver to the client in the present scenario?
Op 1: Code A Op 2: Code B
3: Both codes have the same execution time, so deliver any. Op 4: None of these
Correct Op : 1
Q) Code A has to execute 4*n2 + 64 program statements, while Code B has to execute 32*n program statements for a problem of size n. The time for executing a single program statement is same for all statements. Rajesh was given a problem with a certain size k and he delivered Code A. What could be the possible value of k?
Op 1: 1000 Op 2: 5 Op 3: 10 Op 4: 3
Correct Op : 4
Q) Ravi is writing a program in C++. C++ uses the 'for' keyword for loops. Due to distraction, Ravi writes 'gor' instead of 'for'. What will this result to?
Op 1: The code will not compile.
Op 2: The code will give an error while in execution
Op 3: The code may work for some inputs and not for others.
Op 4: It will create no problems.
Correct Op : 1
Q) What does a compiler do?
Op 1: Converts code from a high level language to a low level language
Op 2: Necessarily converts the code into assembly language
Op 3: Converts code from a low level language to a high level language
Op 4: Necessarily converts the code into machine language
Correct Op : 1
Q) A program is compiled by Tarun on his machine. Whether it will run on a different computer will depend upon:
Op 1: Operating system on the computer
Op 2: Hardware configuration of the computer
Op 3: Both operating system and hardware configuration
Op 4: The language of the program
Correct Op : 3
Q) Sakshi writes a code in a high-level programming language on a Pentium-III machine, which she wants to execute on a Motorola chip. What of the following will she run on the code?
Op 1: An interpreter Op 2: A compiler
Op 3: A cross-compiler Op 4: Linker
Correct Op : 3
Q) Shahaana has a 10,000 line code. She is trying to debug it. She knows there is a logical error in the first 25 lines of the code. Which of the following will be an efficient way of debugging:
Op 1: Compile the whole code and step into it line by line
Op 2: Use an interpreter on the first 25 lines.
Op 3: Compile the whole code and run it
Op 4: None of these
Correct Op : 2
Q) Farhan writes a code to find the factorial of an inputted number. His code gives correct answer for some inputs and incorrect answers for others. What kind of error does his program have?
Op 1: Syntactical error Op 2: Run-time Error
Op 3: Logical Error Op 4: None of these
Correct Op : 3
Q) Reshama is debugging a piece of code which takes several iterations of modifying and executing code, while Mohammad has to deliver a product to the customer, which the customer will run multiple times. Reshama wants her debug cycle to take minimum possible time, while Mohammad wants that his products run time is minimum. What tools should Reshama and Mohammad respectively use on their code?
Op 1: Compiler, Interpreter Op 2: Interpreter, Compiler
Op 3: Compiler, Compiler Op 4: Interpreter, Interpreter
Correct Op : 2
Q) Gautam writes a program to run on a Motorola processor on his Pentium computer. He wants to see how the program will execute on the Motorola processor using his Pentium machine. What tool will he use?
Op 1: Compiler Op 2: Interpreter
Op 3: Assembler Op 4: Simulator
Correct Op : 4
Q) Which one of the following is the lowest level format to which the computer converts a higher language program before execution?
Op 1: English code Op 2: Machine Code
Op 3: Assembly Language Op 4: System Language
Correct Op : 2