C Programming questions

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

0/60 correct0 marks

Related topics in Programming and Data Structures