C Programming Miscellaneous GATE CS PYQ Quiz

Last Updated :
Discuss
Comments

Question 1

Consider the C program below. 
 

C
#include <stdio.h>
int *A, stkTop;
int stkFunc (int opcode, int val)
{
    static int size=0, stkTop=0;
    switch (opcode)
    {
    case -1:
        size = val;
        break;
    case 0:
        if (stkTop < size ) A[stkTop++]=val;
        break;
    default:
        if (stkTop) return A[--stkTop];
    }
    return -1;
}
int main()
{
    int B[20];
    A=B;
    stkTop = -1;
    stkFunc (-1, 10);
    stkFunc (0, 5);
    stkFunc (0, 10);
    printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));
}

The value printed by the above program is ___________
 

  • 9

  • 10

  • 15

  • 17

Question 2

Which combination of the integer variables x, y and z makes the variable a get the value 4 in the following expression?

C
a = ( x > y ) ? (( x > z ) ? x : z) : (( y > z ) ? y : z )
  • x = 3, y = 4, z = 2

  • x = 6, y = 5, z = 3

  • x = 6, y = 3, z = 5

  • x = 5, y = 4, z = 5

Question 3

Consider the following pseudo code. What is the total number of multiplications to be performed?

D = 2
for i = 1 to n do
for j = i to n do
for k = j + 1 to n do
D = D * 3
  • Half of the product of the 3 consecutive integers.

  • One-third of the product of the 3 consecutive integers.

  • One-sixth of the product of the 3 consecutive integers.

  • None of the above.

Question 4

In the above question, if array A is made to hold the string “abcde”, which of the above four test cases will be successful in exposing the flaw in this procedure?

  • None

  • 2 Only

  • 3 and 4 only

  • 4 only

Question 5

What is the return value of f(p,p), if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value.

CPP
int f(int &x, int c) {
   c = c - 1;
   if (c==0) return 1;
   x = x + 1;
   return f(x,c) * x;
}
  • 3024

  • 6561

  • 55440

  • 161051

Question 6

The most appropriate matching for the following pairs

X: Indirect addressing            1 : Loops

Y: Immediate addressing 2 : Pointers

Z: Auto decrement addressing 3: Constants

is

  • X-3, Y-2, Z-1

  • X-I, Y-3, Z-2

  • X-2, Y-3, Z-1

  • X-3, Y-l, Z-2

Question 7

The attributes of three arithmetic operators in some programming language are given below.


Operator Precedence Associativity Arity
+ High Left Binary
- Medium Right Binary
* Low Left Binary

The value of the expression 2 - 5 + 1 - 7 * 3 in this language is __________ ?   Note : This question was asked as Numerical Answer Type.

  • 1

  • 2

  • 3

  • 9

Question 8

What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed?

a=3;
void n(x) {x = x * a; print(x);}
void m(y) {a = 1; a = y - a; n(a); print(a);}
void main() {m(a);}
  • 6, 2

  • 6, 6

  • 4, 2

  • 4, 4

Question 9

Which of the following statements is FALSE ?

  • In statically typed language, each variable in a program has a fixed type

  • In un-typed languages, values do not have any types

  • In dynamically typed languages, variables have no types

  • In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program

Question 10

Which of the following are true?

I. A programming language which does not permit global variables of any
kind and has no nesting of procedures/functions, but permits recursion
can be implemented with static storage allocation
II. Multi-level access link (or display) arrangement is needed to arrange
activation records only if the programming language being implemented
has nesting of procedures/functions
III. Recursion in programming languages cannot be implemented with dynamic
storage allocation
IV. Nesting of procedures/functions and recursion require a dynamic heap
allocation scheme and cannot be implemented with a stack-based allocation
scheme for activation records
V. Programming languages which permit a function to return a function as its
result cannot be implemented with a stack-based storage allocation scheme
for activation records
  • II and V only

  • I, III and IV only

  • I, II and V only

  • II, III and V only

There are 20 questions to complete.

Take a part in the ongoing discussion