1
GATE CSE 2024 Set 2
MCQ (Single Correct Answer)
+1
-0.33

Consider the following C program. Assume parameters to a function are evaluated from right to left.


#include <studio.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?

A

20101020

B

10202010

C

20102010

D

10201020

2
GATE CSE 2024 Set 2
MCQ (More than One Correct Answer)
+1
-0.33

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?

A

The function call fX("abcd") will always return a value

B

Assuming a character array c is declared as char c[] = "abcd" in main(), the function call fX(c) will always return a value

C

The code of the function will not compile

D

Assuming a character pointer c is declared as char *c = "abcd" in main(), the function call fX(c) will always return a value

3
GATE CSE 2024 Set 2
MCQ (Single Correct Answer)
+2
-0.66

What is the output of the following C program?


#include <studio.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;}
A

4,8

B

1,5

C

8,5

D

1,8

4
GATE CSE 2024 Set 2
MCQ (Single Correct Answer)
+2
-0.66

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) and (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.)

A

(P) len1+1 (Q) len2+1

B

(P) 1 (Q) len1+1

C

(P) 1 (Q) len2+1

D

(P) len2+1 (Q) len1+1

EXAM MAP
Medical
NEETAIIMS
Graduate Aptitude Test in Engineering
GATE CSEGATE ECEGATE EEGATE MEGATE CEGATE PIGATE IN
Civil Services
UPSC Civil Service
Defence
NDA
Staff Selection Commission
SSC CGL Tier I
CBSE
Class 12