C Programming questions — page 3 of 4

Q12

GATE CS 2016 CS-1C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program.
void f(int, short);
void main()
{
    int i = 100;
    short s = 12;
    short *p = &s;
    __________ ;    // call to f()
}
Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?
Show answer without attempting

Answer: D

Q15

GATE CS 2016 CS-1C ProgrammingNAT1 mark
Consider the following C program.
#include<stdio.h>
void mystery(int *ptra, int *ptrb) {
    int *temp;
    temp = ptrb;
    ptrb = ptra;
    ptra = temp;
}
int main() {
    int a=2016, b=0, c=4, d=42;
    mystery(&a, &b);
    if (a < c)
        mystery(&c, &a);
    mystery(&a, &d);
    printf("%d\n", a);
}
The output of the program is ________.
Show answer without attempting

Answer: 2016.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

Q12

GATE CS 2016 CS-2C ProgrammingNAT1 mark
The value printed by the following program is _________.
void f(int* p, int m){
    m = m + 5;
    *p = *p + m;
    return;
}

void main(){
    int i=5, j=10;
    f(&i, j);
    printf("%d", i+j);
}
Show answer without attempting

Answer: 30.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

Q43

GATE CS 2015 CS-3C ProgrammingNAT2 marks
Consider the following C program.
#include<stdio.h>
int main( )
{
    static int a[ ] = {10, 20, 30, 40, 50};
    static int *p[ ] = {a, a+3, a+4, a+1, a+2};
    int **ptr = p;
    ptr++;
    printf("%d%d", ptr-p, **ptr);
}
The output of the program is ____________.
Show answer without attempting

Answer: 140

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

Q16

GATE CS 2015 CS-1C ProgrammingMCQ1 mark−1/3 if wrong
Match the following:

(P) Condition coverage
(Q) Equivalence class partitioning
(R) Volume testing
(S) Alpha testing

(i) Black-box testing
(ii) System testing
(iii) White-box testing
(iv) Performance testing
Show answer without attempting

Answer: C

Q34

GATE CS 2015 CS-1C ProgrammingNAT1 mark
The output of the following C program is ________.
void f1(int a, int b) {
    int c;
    c = a; a = b; b = c;
}
void f2(int *a, int *b) {
    int c;
    c = *a; *a = *b; *b = c;
}
int main() {
    int a = 4, b = 5, c = 6;
    f1(a, b);
    f2(&b, &c);
    printf("%d", c - a - b);
}
Show answer without attempting

Answer: -5

Q62

GATE CS 2015 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory.
int main() {
    unsigned int x[4][3] =
        {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
    printf("%u, %u, %u", x+3, *(x+3), *(x+2)+3);
}
Show answer without attempting

Answer: A

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

Q21

GATE CS 2015 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following function written in the C programming language.
void foo(char *a){
    if ( *a && *a != ' '){
        foo(a+1);
        putchar(*a);
    }
}
The output of the above function on input "ABCD EFGH" is
Show answer without attempting

Answer: D

Q25

GATE CS 2015 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
A software requirements specification (SRS) document should avoid discussing which one of the following?
Show answer without attempting

Answer: C

Q29

GATE CS 2015 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the basic COCOMO model where EE is the effort applied in person-months, DD is the development time in chronological months, KLOCKLOC is the estimated number of delivered lines of code (in thousands) and ab,bb,cb,dba_b, b_b, c_b, d_b have their usual meanings. The basic COCOMO equations are of the form
Show answer without attempting

Answer: A

Q64

GATE CS 2015 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
Which one of the following assertions concerning code inspection and code walkthrough is true?
Show answer without attempting

Answer: C

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

0/200 correct0 marks

Related topics in Programming and Data Structures