C Expressions and Control Flow questions — page 2 of 2

Q55

GATE CS 2017 CS-1C ProgrammingNAT2 marks
The output of executing the following C program is ____________.
#include <stdio.h>

int total(int v) {
    static int count = 0;
    while(v) {
        count += v&1;
        v >>= 1;
    }
    return count;
}

void main() {
    static int x = 0;
    int i = 5;
    for(; i > 0; i--) {
        x = x + total(i);
    }
    printf("%d\n", x);
}
Show answer without attempting

Answer: 23.0

Q37

GATE CS 2017 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
Consider the C program fragment below which is meant to divide xx by yy using repeated subtractions. The variables x,y,qx, y, q and rr are all unsigned int.
while (r >= y) {
    r = r - y;
    q = q + 1;
}
Which of the following conditions on the variables x,y,qx, y, q and rr before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition x == (y*q + r)?
Show answer without attempting

Answer: C

Q54

GATE CS 2017 CS-2C ProgrammingNAT2 marks
Consider the following C Program.
#include <stdio.h>
int main() {
    int m = 10;
    int n, n1;
    n = ++m;
    n1 = m++;
    n--;
    --n1;
    n -= n1;
    printf("%d", n);
    return 0;
}
The output of the program is ____________.
Show answer without attempting

Answer: 0.0

Q35

GATE CS 2016 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
What will be the output of the following C program?
void count(int n){
    static int d=1;

    printf("%d ", n);
    printf("%d ", d);
    d++;
    if(n>1) count(n-1);
    printf("%d ", d);
}

void main(){
    count(3);
}
Show answer without attempting

Answer: A

Q45

GATE CS 2016 CS-1C ProgrammingNAT2 marks
The attributes of three arithmetic operators in some programming language are given below.
OperatorPrecedenceAssociativityArity
++HighLeftBinary
−-MediumRightBinary
∗*LowLeftBinary
The value of the expression 2−5+1−7∗32-5+1-7*3 in this language is ________.
Show answer without attempting

Answer: 9.0

Q35

GATE CS 2016 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
The following function computes XYX^Y for positive integers XX and YY.
int exp(int X, int Y) {
    int res = 1, a = X, b = Y;
    while ( b != 0 ){
        if ( b%2 == 0) { a = a*a; b = b/2; }
        else { res = res*a; b = b-1; }
    }
    return res;
}
Which one of the following conditions is TRUE before every iteration of the loop?
Show answer without attempting

Answer: C

Q11

GATE CS 2015 CS-3C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program segment.
#include <stdio.h>

int main()
{
    char s1[7] = "1234", *p;
    p = s1 + 2;
    *p = '0';
    printf("%s", s1);
}
What will be printed by the program?
Show answer without attempting

Answer: C

Q42

GATE CS 2015 CS-3C ProgrammingNAT2 marks
Consider the following C program.
#include <stdio.h>
int f1(void);
int f2(void);
int f3(void);
int x = 10;

int main ( )
{
    int x = 1;
    x += f1() + f2() + f3() + f2();
    printf("%d", x);
    return 0;
}

int f1() { int x = 25; x++; return x;}
int f2() { static int x = 50; x++; return x;}
int f3() { x *= 10; return x;}
The output of the program is ____________.
Show answer without attempting

Answer: 230

Q53

GATE CS 2015 CS-3C ProgrammingNAT2 marks
Consider the following C program:
#include<stdio.h>
int main( )
{
    int i, j, k = 0;
    j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
    k -= --j;
    for(i = 0; i < 5; i++)
    {
        switch(i + k)
        {
            case 1:
            case 2: printf("\n%d", i+k);
            case 3: printf("\n%d", i+k);
            default: printf("\n%d", i+k);
        }
    }
    return 0;
}
The number of times printf statement is executed is ____________.
Show answer without attempting

Answer: 10

Q65

GATE CS 2015 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
Consider the following pseudo code, where xx and yy are positive integers.
begin
  q := 0
  r := x
  while r >= y do
    begin
      r := r - y
      q := q + 1
    end
end
The post condition that needs to be satisfied after the program terminates is
Show answer without attempting

Answer: B

Q10

GATE CS 2014 CS-2C ProgrammingNAT1 mark
Consider the function func shown below:
int func(int num) {
int count = 0;
    while (num) {
       count++;
       num>>= 1;
    }
return (count);
}
The value returned by func(435) is __________.
Show answer without attempting

Answer: 9

Q11

GATE CS 2014 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Suppose n and p are unsigned int variables in a C program. We wish to set p to nC3^{n}C_{3}. If n is large, which one of the following statements is most likely to set p correctly?
Show answer without attempting

Answer: B

Q42

GATE CS 2013 CSC ProgrammingMCQ2 marks−2/3 if wrong
What is the return value of f(p,p), if the value of pp is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value.
int f (int &x, int c) {
  c = c - 1;
  if (c==0) return 1;
  x = x + 1;
  return f(x,c) * x;
}
Show answer without attempting

Answer: Marks to all

Q50

GATE CS 2013 CSC ProgrammingMCQ2 marks−2/3 if wrong
The tester now tests the program on all input strings of length five consisting of characters 'a', 'b', 'c', 'd' and 'e' with duplicates allowed. If the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw?
Show answer without attempting

Answer: B

Q51

GATE CS 2013 CSC ProgrammingMCQ2 marks−2/3 if wrong
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?
Show answer without attempting

Answer: C

Q3

GATE CS 2012 CSC ProgrammingMCQ1 mark−1/3 if wrong
What will be the output of the following C program segment?
char inChar = 'A' ;
switch ( inChar ) {
case 'A' : printf ("Choice A\ n") ;
case 'B' :
case 'C' : printf ("Choice B") ;
case 'D' :
case 'E' :
default  : printf ( " No Choice" ) ; }
Show answer without attempting

Answer: Marks to all

Q49

GATE CS 2012 CSC ProgrammingMCQ2 marks−2/3 if wrong
What output will be generated by the given code segment if:
Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;
Show answer without attempting

Answer: D

0/170 correct0 marks

Related topics in C Programming