• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Quiz - 113 1

Question 1

Output of following program under the assumption that numbers are stored in 2\'s complement form. C
#include<stdio.h>
int main()
{
   printf(\"%c\\n\", ~(\'C\' * -1));
   return 0;
}
Contributed by Sowmya.L.R
  • B
  • A
  • Compiler Error
  • C

Question 2

The function f is defined as follows: 

C
int f (int n) {
    if (n <= 1) return 1;
    else if (n % 2  ==  0) return f(n/2);
    else return f(3n - 1);
}

Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
1. The function f terminates for finitely many different values of n ≥ 1. 
ii. The function f terminates for infinitely many different values of n ≥ 1. 
iii. The function f does not terminate for finitely many different values of n ≥ 1. 
iv. The function f does not terminate for infinitely many different values of n ≥ 1. 
Which one of the following options is true of the above?

  • (i) and (iii)

  • (i) and (iv)

  • (ii) and (iii)

  • (ii) and (iv)

Question 3

Consider the program below in a hypothetical language which allows global variable and a choice of call by reference or call by value methods of parameter passing. C
 int i ;
program main ()
{
    int j = 60;
    i = 50;
    call f (i, j);
    print i, j;
}
procedure f (x, y)
{           
    i = 100;
    x = 10;
    y = y + i ;
}
Which one of the following options represents the correct output of the program for the two parameter passing mechanisms?
  • Call by value : i = 70, j = 10; Call by reference : i = 60, j = 70
  • Call by value : i = 50, j = 60; Call by reference : i = 50, j = 70
  • Call by value : i = 10, j = 70; Call by reference : i = 100, j = 60
  • Call by value : i = 100, j = 60; Call by reference : i = 10, j = 70

Question 4

What is the output printed by the following C code? C
# include <stdio.h>
int main ()
{
    char a [6] = \"world\";
    int i, j;
    for (i = 0, j = 5; i < j; a [i++] = a [j--]);
    printf (\"%s\\n\", a);
}
 /* Add code here. Remove these lines if not writing code */ 
  • dlrow
  • Null String
  • dlrld
  • worow

Question 5

Consider the C program below. What does it print? C
# include <stdio.h>
# define swapl (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
        int tmp;
        tmp = a; a = b; b = tmp;
 }
void swap3 (int*a, int*b)
{
        int tmp;
        tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
        int num1 = 5, num2 = 4, tmp;
        if (num1 < num2) {swap1 (num1, num2);}
        if (num1 < num2) {swap2 (num1 + 1, num2);}
        if (num1 >= num2) {swap3 (&num1, &num2);}
        printf (\"%d, %d\", num1, num2);
}
 /* Add code here. Remove these lines if not writing code */ 
  • 5, 5
  • 5, 4
  • 4, 5
  • 4, 4

Question 6

Consider the C program given below. What does it print? C
#include <stdio.h>
int main ()
{
        int i, j;
        int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};
        for(i = 0; i < 3; i++) {
             a[i] = a[i] + 1;
             i++;
        }
        i--;
        for (j = 7; j > 4; j--) {
              int i = j/2;
              a[i] = a[i] - 1;
        }
        printf (\"%d, %d\", i, a[i]);
}
 /* Add code here. Remove these lines if not writing code */ 
  • 2, 3
  • 2, 4
  • 3, 2
  • 3, 3

Question 7

Consider the following C code:
 int A[100][100];
 int main()
 {
    for(int i=1; i < 100 ; i++)
        for(int j=1; j < 100;j++)
            A[i][j] = (i/j)*(j/i);
   return 0;
 }

What will be the sum of the all the elements of double dimensional array A after implementing the above function ?
  • 100
  • 99
  • (100*99)/2
  • 0

Question 8

Consider the following C program: C
#include <stdio.h>

int counter = 0;

int calc(int a, int b) {
  int c;

  counter++;
  if (b == 3)
    return (a * a * a);
  else {
    c = calc(a, b / 3);
    return (c * c * c);
  }
}

int main() {
  calc(4, 81);
  printf(\"%d\", counter);
}
The output of this program is ________ . Note - This was Numerical Type question.
  • 5
  • 4
  • 3
  • None of these

Question 9

Consider the following C program: C
   #include 
           #define EOF -1
           void push (int); /* push the argument on the stack */
           int pop  (void); /* pop the top of the stack */
           void flagError ();
           int main ()
          {         int c, m, n, r;
                     while ((c = getchar ()) != EOF)
                    { if  (isdigit (c) )
                               push (c);
                     else if ((c == \'+\') || (c == \'*\'))
                    {          m = pop ();
                                n = pop ();
                                r = (c == \'+\') ? n + m : n*m;
                                push (r);
                      }
                      else if (c != \' \')
                               flagError ();
             }
              printf(\"% c\", pop ());
}
What is the output of the program for the following input ? 5 2 * 3 3 2 + * +
  • 15
  • 25
  • 30
  • 150

Question 10

Consider the following C program. C
#include <stdio.h>
struct Ournode {
  char x, y, z;
};

int main() {
  struct Ournode p = {\'1\', \'0\', \'a\' + 2};
  struct Ournode *q = &p;
  printf(\"%c, %c\", *((char *)q + 1), *((char *)q + 2));
  return 0;
}
The output of this program is:
  • 0, c
  • 0, a+2
  • \'0\', \'a+2\'
  • \'0\', \'c\'

There are 10 questions to complete.

Last Updated :
Take a part in the ongoing discussion