• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Quiz - 113

Question 1

C program is given below: C
# include <stdio.h>
int main ()
{
        int i, j;
        char a [2] [3] = {{\'a\', \'b\', \'c\'}, {\'d\', \'e\', \'f\'}};
        char b [3] [2];
        char *p = *b;
        for (i = 0; i < 2; i++) {
              for (j = 0; j < 3; j++) {
              *(p + 2*j + i) = a [i] [j];
              }
        }
}
 /* Add code here. Remove these lines if not writing code */ 
What should be the contents of the array b at the end of the program?
  • a b
    c d
    e f
  • a d
    b e
    c f
  • a c
    e b
    d f
  • a e
    d c
    b f

Question 2

Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are: 
i. isEmpty (Q) — returns true if the queue is empty, false otherwise. 
ii. delete (Q) — deletes the element at the front of the queue and returns its value. 
iii. insert (Q, i) — inserts the integer i at the rear of the queue. 
Consider the following function: 

C
 void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
   i = delete(Q);
   f(Q);
   insert(Q, i);
  }
}

What operation is performed by the above function f ?

  • Leaves the queue Q unchanged

  • Reverses the order of the elements in the queue Q

  • Deletes the element at the front of the queue Q and inserts it at the rear keeping the other elements in the same order

  • Empties the queue Q

Question 3

Consider the C program given below : C
 #include <stdio.h>
int main ()    {
    int sum = 0, maxsum = 0,  i,  n = 6;
    int a [] = {2, -2, -1, 3, 4, 2};
    for (i = 0; i < n; i++)    {
            if (i == 0 || a [i]  < 0  || a [i] < a [i - 1])  {
                     if (sum > maxsum) maxsum = sum;
                     sum = (a [i] > 0) ? a [i] : 0;
            }
            else sum += a [i];
    }
    if (sum > maxsum) maxsum = sum ;
    printf (\"%d\\n\", maxsum);

} 
What is the value printed out when this program is executed?
  • 9
  • 8
  • 7
  • 6

Question 4

C
#include <stdio.h>

int main()
{
    unsigned int i = 65000;
    while (i++ != 0);
    printf(\"%d\", i);
    return 0;
}
  • Infinite Loop
     

  • 0
     


  •  

  • Run Time Error
     

There are 4 questions to complete.

Last Updated :
Take a part in the ongoing discussion