Array and Pointer: GATE CS Previous Year Questions

Array and Pointer · Programming in C

54 questions · asked in 22 of 27 years (2000–2026)

MCQ 39 · MSQ 1 · NAT 141-mark 34 · 2-mark 20

2000Questions per year2026

Questions 16–20 of 54

Q16GATE 20182 marksMCQ−0.67 if wrong
Consider the following C program:

#include <stdio.h>
void fun1(char *s1, char *s2){
char *tmp;
tmp = s1;
s1 = s2;
s2 = tmp;
}
void fun2(char **s1, char **s2){
char *tmp;
tmp = *s1;
*s1 = *s2;
*s2 = tmp;
}
int main(){
char *str1 = "Hi", *str2 = "Bye";
fun1(str1, str2); 
printf("%s %s ", str1, str2); 
fun2(&str1, &str2); 
printf("%s %s", str1, str2);
return 0;
}
The output of the program above is

Q17GATE 2017 (Session 1)1 markMCQ−0.33 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:

Q18GATE 2017 (Session 1)2 marksNAT
Consider the following C program.
 #include <stdio.h>
#include <string.h>
void printlength (char *s, char *t) {
 unsigned int c = 0;
 int len = ((strlen(s) - strlen (t)) > c) ? strlen(s): strlen(t);
 printf ("%d\n", len);
}
void main ( ) {
 char *x = "abc";
 char *y ="defgh"; 
 printlength (x,y);
}
Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int. The output of the program is _____________.

Q19GATE 2017 (Session 2)1 markMCQ−0.33 if wrong
Match the following:
(P) static char var;(i) Sequence of memory locations to store addresses
(Q) m = malloc(10);
m = NULL;
(ii) A variable located in data section of memory
(R) char *ptr[10];(iii) Request to allocate a CPU register to store data
(S) register int var1;(iv) A lost memory which cannot be freed

Q20GATE 2017 (Session 2)1 markMCQ−0.33 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

Keep practising

Topics in Programming in C

All CS topics ›