C Programming questions

Q18

GATE CS 2024 CS-1C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program:
#include <stdio.h>
int main(){
 int a = 6;
 int b = 0;
 while(a < 10) {
 a = a / 12 + 1;
 a += b;
 }
 printf("%d", a);
 return 0;
}
Which one of the following statements is CORRECT?
Show answer without attempting

Answer: C

Q48

GATE CS 2024 CS-1C ProgrammingMSQ2 marks
Consider the following C function definition.
int f(int x, int y) {
 for (int i=0; i<y; i++) {
 x=x+x+y;
 }
 return x;
}
Which of the following statements is/are TRUE about the above function?
More than one option can be correct.
Show answer without attempting

Answer: B, D

Q13

GATE CS 2024 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program. Assume parameters to a function are evaluated from right to left.
#include <stdio.h>
int g(int p) { printf("%d", p); return p; }
int h(int q) { printf("%d", q); return q; }
void f(int x, int y) {
    g(x);
    h(y);
}
int main() {
    f(g(10),h(20));
}
Which one of the following options is the CORRECT output of the above C program?
Show answer without attempting

Answer: A

Q33

GATE CS 2024 CS-2C ProgrammingMSQ1 mark
Consider the following C function definition.
int fX(char *a){
    char *b = a;
    while(*b)
        b++;
    return b - a;
}
Which of the following statements is/are TRUE?
More than one option can be correct.
Show answer without attempting

Answer: A, B, D

Q36

GATE CS 2024 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
What is the output of the following C program?
#include <stdio.h>
int main() {
    double a[2]={20.0, 25.0}, *p, *q;
    p = a;
    q = p + 1;
    printf("%d,%d", (int)(q - p), (int)(*q - *p));
    return 0;
}
Show answer without attempting

Answer: B

Q42

GATE CS 2024 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
Consider an array X that contains n positive integers. A subarray of X is defined to be a sequence of array locations with consecutive indices.

The C code snippet given below has been written to compute the length of the longest subarray of X that contains at most two distinct integers. The code has two missing expressions labelled (P)(P) and (Q)(Q).
int first=0, second=0, len1=0, len2=0, maxlen=0;
for (int i=0; i < n; i++) {
    if (X[i] == first) {
        len2++; len1++;
    } else if (X[i] == second) {
        len2++;
        len1 = (P) ;
        second = first;
    } else {
        len2 = (Q) ;
        len1 = 1; second = first;
    }
    if (len2 > maxlen) {
        maxlen = len2;
    }
    first = X[i];
}
Which one of the following options gives the CORRECT missing expressions?

(Hint: At the end of the i-th iteration, the value of len1 is the length of the longest subarray ending with X[i] that contains all equal values, and len2 is the length of the longest subarray ending with X[i] that contains at most two distinct values.)
Show answer without attempting

Answer: B

0/60 correct0 marks

Related topics in Programming and Data Structures