Functions and Pointers questions

Q11

GATE CS 2015 CS-3C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program segment.
#include <stdio.h>

int main()
{
    char s1[7] = "1234", *p;
    p = s1 + 2;
    *p = '0';
    printf("%s", s1);
}
What will be printed by the program?
Show answer without attempting

Answer: C

Q42

GATE CS 2015 CS-3C ProgrammingNAT2 marks
Consider the following C program.
#include <stdio.h>
int f1(void);
int f2(void);
int f3(void);
int x = 10;

int main ( )
{
    int x = 1;
    x += f1() + f2() + f3() + f2();
    printf("%d", x);
    return 0;
}

int f1() { int x = 25; x++; return x;}
int f2() { static int x = 50; x++; return x;}
int f3() { x *= 10; return x;}
The output of the program is ____________.
Show answer without attempting

Answer: 230

Q43

GATE CS 2015 CS-3C ProgrammingNAT2 marks
Consider the following C program.
#include<stdio.h>
int main( )
{
    static int a[ ] = {10, 20, 30, 40, 50};
    static int *p[ ] = {a, a+3, a+4, a+1, a+2};
    int **ptr = p;
    ptr++;
    printf("%d%d", ptr-p, **ptr);
}
The output of the program is ____________.
Show answer without attempting

Answer: 140

Q34

GATE CS 2015 CS-1C ProgrammingNAT1 mark
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);
}
Show answer without attempting

Answer: -5

Q62

GATE CS 2015 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory.
int main() {
    unsigned int x[4][3] =
        {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
    printf("%u, %u, %u", x+3, *(x+3), *(x+2)+3);
}
Show answer without attempting

Answer: A

Q21

GATE CS 2015 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
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
Show answer without attempting

Answer: D

0/60 correct0 marks

Related topics in C Programming