C Programming GATE previous year questions with answer

Ques 53 Gate 2015 Set-2


Consider the following function written in the C programming language.

void foo (char *a)
{
    if (*a && *a != ` `)
    {
        foo(a+1);
        putchar(*a);
    }
}


The output of the above function on input “ABCD  EFGH” is

A

ABCD EFGH

B

ABCD

C

HGFE DCBA

D

DCBA


(C Code) is the correct answer.

PROCESSED

Ques 54 Gate 2015 Set-1


The output of the following C program is __________.

void f1 (int a, int b)
{
    int c;
    c=a; a=b; b=c;
}
void f2 (int *a, int *b)
{
    int c;
   c=*a; *a=*b;*b=c;
}
int main()
{
    int a=4, b=5, c=6;
    f1(a, b);
    f2(&b, &c);
    printf (“%d”, c-a-b);
    return 0;
}


(a) is the correct answer.

Ques 55 Gate 2015 Set-1


Which of following statements is/are False?

I. XML overcomes the limitations in HTML to support a structured way of organizing content.
II. XML specification is not case sensitive while HTML specification is case sensitive.
III. XML supports user defined tags while HTML uses pre-defined tags.
IV. XML tags need not be closed while HTML tags must be closed.

A

II only

B

I only

C

I and IV only

D

III and IV only


(1) is the correct answer.

Ques 56 Gate 2014 Set-1


Consider the following program in C language:

#include <stdio.h>
main()
{
    int i;
    int *pi = &i;
    scanf("%d", pi);
    printf("%d∖n", i+5);
}


Which one of the following statements is TRUE?

A

Compilation fails.

B

Execution results in a run-time error.

C

On execution, the value printed is 5 more than the address of variable i.

D

On execution, the value printed is 5 more than the integer value entered.


(C Code) is the correct answer.

The program stores the integer entered by the user in variable i using the pointer pi. The program then calculates i + 5 and prints the result.
Solution:
pi = &i means that pi stores the address of i.
When scanf("%d", pi) is executed, the integer entered by the user is stored in i.
The statement printf("%d\n", i + 5) then prints the value of i + 5.
Example: If the user enters 10, then i = 10 and the output is 15.
Analyze the Options:
A) Compilation fails: Incorrect. The program is valid C code.
B) Execution results in a run-time error: Incorrect. The pointer correctly points to variable i.
C) The value printed is 5 more than the address of variable i: Incorrect. The program prints i + 5, not the address of i.
D) The value printed is 5 more than the integer value entered: Correct. The entered value is stored in i, and then 5 is added to it.
Correct Answer: D) On execution, the value printed is 5 more than the integer value entered.

Unique Visitor Count

Total Unique Visitors

Loading......