Functions and Pointers questions — page 1 of 2

Q60

GATE CS 2026 CS-2C ProgrammingNAT2 marks
Consider the following ANSI-C program.
#include <stdio.h>
int main(){
 int *ptr, a, b, c;
 a=5; b=11; c=20;
 ptr=&a; *ptr=c; ptr=&c;
 a=*(&b); c=*ptr-a;
 printf("%d",c);
 return(0);
}
The output of this program is ____________. (answer in integer)

Note: Assume that the program compiles and runs successfully.
Show answer without attempting

Answer: 9

Q34

GATE CS 2025 CS-1C ProgrammingNAT1 mark
#include <stdio.h>
void foo(int *p, int x){
 *p=x;
}
int main(){
 int *z;
 int a = 20, b = 25;
 z = &a;
 foo(z,b);
 printf("%d",a);
 return 0;
}
The output of the given C program is __________. (Answer in integer)
Show answer without attempting

Answer: 25

Q19

GATE CS 2025 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program:
#include <stdio.h>
void stringcopy(char *, char *);
int main(){
    char a[30] = "@#Hello World!";
    stringcopy(a, a + 2);
    printf("%s\n", a);
    return 0;
}
void stringcopy(char *s, char *t) {
    while(*t)
        *s++ = *t++;
}
Which ONE of the following will be the output of the program?
Show answer without attempting

Answer: D

Q62

GATE CS 2025 CS-2C ProgrammingNAT2 marks
Consider the following C program:
#include <stdio.h>
int main(){
    int a;
    int arr[5] = {30,50,10};
    int *ptr;
    ptr = &arr[0] + 1;
    a = *ptr;
    (*ptr)++;
    ptr++;
    printf("%d", a + (*ptr) + arr[1]);
    return 0;
}
The output of the above program is ___________. (Answer in integer)
Show answer without attempting

Answer: 111

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

Q35

GATE CS 2023 CSC ProgrammingNAT1 mark
The integer value printed by the ANSI-C program given below is ____________.
#include<stdio.h>
int funcp(){
static int x = 1;
x++;
return x;
}
int main(){
int x,y;
x = funcp();
y = funcp()+x;
printf("%d\n", (x+y));
return 0;
}
Show answer without attempting

Answer: 7

Q21

GATE CS 2022 CSC ProgrammingMCQ1 mark−1/3 if wrong
What is printed by the following ANSI C program?
#include<stdio.h>
int main(int argc, char *argv[])
{
  int x = 1, z[2] = {10, 11};
  int *p = NULL;
  p = &x;
  *p = 10;
  p = &z[1];
  *(&z[0] + 1) += 3;
  printf("%d, %d, %d\n", x, z[0], z[1]);
  return 0;
}
Show answer without attempting

Answer: D

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

Q22

GATE CS 2020 CSC ProgrammingNAT1 mark
Consider the following C program.
#include <stdio.h>
int main() {
    int a[4][5]={{1, 2, 3, 4, 5},
                 {6, 7, 8, 9, 10},
                 {11, 12, 13, 14, 15},
                 {16, 17, 18 , 19, 20}};
    printf("%d\n", *(*(a+**a+2)+3));
    return(0);
}
The output of the program is __________.
Show answer without attempting

Answer: 19

Q48

GATE CS 2020 CSC ProgrammingNAT2 marks
Consider the following C functions.
int tob(int b, int* arr) {
    int i;
    for (i=0; b>0; i++) {
        if (b%2) arr[i]=1;
        else     arr[i]=0;
        b = b/2;
    }
    return(i);
}

int pp(int a, int b) {
    int arr[20];
    int i, tot = 1, ex, len;
    ex = a;
    len = tob(b,arr);
    for (i=0; i<len; i++) {
        if (arr[i]==1)
            tot = tot * ex;
        ex = ex * ex;
    }
    return(tot);
}
The value returned by pp(3,4) is __________.
Show answer without attempting

Answer: 81

Q18

GATE CS 2019 CSC ProgrammingNAT1 mark
Consider the following C program:
#include <stdio.h>
int jumble(int x, int y){
    x = 2*x + y;
    return x;
}
int main(){
    int x=2, y=5;
    y = jumble(y,x);
    x = jumble(y,x);
    printf("%d \n", x);
    return 0;
}
The value printed by the program is __________.
Show answer without attempting

Answer: 26

Q24

GATE CS 2019 CSC ProgrammingNAT1 mark
Consider the following C program:
#include <stdio.h>
int main(){
    int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4;
    printf("%d\n", ip[1]);
    return 0;
}
The number that will be displayed on execution of the program is __________.
Show answer without attempting

Answer: 6

Q27

GATE CS 2019 CSC ProgrammingMCQ2 marks−2/3 if wrong
Consider the following C program:
#include <stdio.h>
int r(){
    static int num=7;
    return num--;
}
int main(){
    for (r();r();r())
        printf("%d",r());
    return 0;
}
Which one of the following values will be displayed on execution of the programs?
Show answer without attempting

Answer: B

Q53

GATE CS 2019 CSC ProgrammingNAT2 marks
Consider the following C program:
#include <stdio.h>
int main()
{
    int a[] = {2, 4, 6, 8, 10};
    int i, sum = 0, *b = a + 4;
    for (i = 0; i < 5; i++)
        sum = sum + (*b - i) - *(b - i);
    printf("%d\n", sum);
    return 0;
}
The output of the above C program is __________.
Show answer without attempting

Answer: 10

Q2

GATE CS 2018 CSC ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program.
#include<stdio.h>
struct Ournode{
 char x,y,z;
};
int main(){
 struct Ournode p = {'1', '0', 'a'+2};
 struct Ournode *q = &p;
 printf ("%c, %c", *((char*)q+1), *((char*)q+2));
 return 0;
}
The output of this program is:
Show answer without attempting

Answer: A

Q29

GATE CS 2018 CSC ProgrammingMCQ2 marks−2/3 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
Show answer without attempting

Answer: A

0/200 correct0 marks

Related topics in C Programming