Functions and Pointers questions

Q13

GATE CS 2017 CS-1C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C code:
#include <stdio.h>
int *assignval(int *x, int val) {
    *x = val;
    return x;
}

void main () {
    int *x = malloc(sizeof(int));
    if (NULL == x) return;
    x = assignval(x, 0);
    if (x) {
        x = (int *)malloc(sizeof(int));
        if (NULL == x) return;
        x = assignval(x, 10);
    }
    printf("%d\n", *x);
    free(x);
}
The code suffers from which one of the following problems:
Show answer without attempting

Answer: D

Q2

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

(P) static char var;
(Q) m = malloc(10); m = NULL;
(R) char *ptr[10];
(S) register int var1;

(i) Sequence of memory locations to store addresses
(ii) A variable located in data section of memory
(iii) Request to allocate a CPU register to store data
(iv) A lost memory which cannot be freed
Show answer without attempting

Answer: A

Q14

GATE CS 2017 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following function implemented in C:
void printxy(int x, int y) {
    int *ptr;
    x = 0;
    ptr = &x;
    y = *ptr;
    *ptr = 1;
    printf("%d,%d", x, y);
}
The output of invoking printxy(1, 1) is
Show answer without attempting

Answer: C

Q55

GATE CS 2017 CS-2C ProgrammingNAT2 marks
Consider the following C Program.
#include <stdio.h>
#include <string.h>
int main() {
    char* c = "GATECSIT2017";
    char* p = c;
    printf("%d", (int)strlen(c+2[p]-6[p]-1));
    return 0;
}
The output of the program is ____________.
Show answer without attempting

Answer: 2.0

0/40 correct0 marks

Related topics in C Programming