C Programming questions

Q37

GATE CS 2021 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
Consider the following ANSI C program.
#include <stdio.h>
int main()
{
    int i, j, count;
    count = 0;
    i = 0;
    for (j = -3; j <= 3; j++)
    {
        if ((j >= 0) && (i++))
            count = count + j;
    }
    count = count + i;
    printf("%d", count);
    return 0;
}
Which one of the following options is correct?
Show answer without attempting

Answer: B

Q48

GATE CS 2021 CS-1C ProgrammingNAT2 marks
Consider the following ANSI C function:
int SimpleFunction(int Y[], int n, int x)
{
  int total = Y[0], loopIndex;
  for (loopIndex = 1; loopIndex <= n - 1; loopIndex++)
       total = x * total + Y[loopIndex];
  return total;
}
Let Z be an array of 10 elements with Z[ii]=1, for all ii such that 0≤i≤90 \le i \le 9. The value returned by SimpleFunction(Z, 10, 2) is ______.
Show answer without attempting

Answer: 1023

Q10

GATE CS 2021 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following ANSI C program:
#include <stdio.h>
int main(){
    int arr[4][5];
    int i, j;
    for (i=0; i<4; i++){
        for (j=0; j<5; j++){
            arr[i][j] = 10*i + j;
        }
    }
    printf("%d", *(arr[1] + 9));
    return 0;
}
What is the output of the above program?
Show answer without attempting

Answer: C

Q35

GATE CS 2021 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
Consider the following ANSI C program:
#include <stdio.h>
#include <stdlib.h>
struct Node{
    int value;
    struct Node *next;
};
int main(){
    struct Node *boxE, *head, *boxN; int index = 0;
    boxE = head = (struct Node *) malloc(sizeof(struct Node));
    head->value = index;
    for (index = 1; index <= 3; index++){
        boxN = (struct Node *) malloc(sizeof(struct Node));
        boxE->next = boxN;
        boxN->value = index;
        boxE = boxN; }
    for (index = 0; index <= 3; index++) {
        printf("Value at index %d is %d\n", index, head->value);
        head = head->next;
        printf("Value at index %d is %d\n", index+1, head->value); }
}
Which one of the statements below is correct about the program?
Show answer without attempting

Answer: D

0/40 correct0 marks

Related topics in Programming and Data Structures