ARRAYS

1. What will be the output of the program ?

#include<stdio.h>

int main()

{

    int a[5] = {5, 1, 15, 20, 25};

    int i, j, m;

    i = ++a[1];

    j = a[1]++;

    m = a[i++];

    printf("%d, %d, %d", i, j, m);

    return 0;

}

A. 2, 1, 15

B. 1, 2, 5

C. 3, 2, 15

D. 2, 3, 20

        

2. What will be the output of the program ?

#include<stdio.h>

int main()

{

    void fun(int, int[]);

    int arr[] = {1, 2, 3, 4};

    int i;

    fun(4, arr);

    for(i=0; i<4; i++)

        printf("%d,", arr[i]);

    return 0;

}

void fun(int n, int arr[])

{

    int *p=0;

    int i=0;

    while(i++ < n)

        p = &arr[i];

    *p=0;

}

A. 2, 3, 4, 5

B. 1, 2, 3, 4

C. 0, 1, 2, 3

D. 3, 2, 1 0

        

3. What will be the output of the program in Turb C (under DOS)?

#include<stdio.h>

int main()

{

    int arr[5], i=0;

    while(i<5)

        arr[i]=++i;

    for(i=0; i<5; i++)

        printf("%d, ", arr[i]);

    return 0;

}

A. 1, 2, 3, 4, 5,

B. Garbage value, 1, 2, 3, 4,

C. 0, 1, 2, 3, 4,

D. 2, 3, 4, 5, 6

        

4. Which of the following is correct way to define the function fun() in the below program?

#include<stdio.h>

int main()

{

    int a[3][4];

    fun(a);

    return 0;

}

A. void fun(int p[][4]){  }

B. void fun(int *p[4]){   }

C. void fun(int *p[][4]){  }

D. void fun(int *p[3][4]){  }

        

5. Which of the following statements are correct about the program below?

#include<stdio.h>

int main()

{

    int size, i;

    scanf("%d", &size);

    int arr[size];

    for(i=1; i<=size; i++)

    {

        scanf("%d", arr[i]);

        printf("%d", arr[i]);

    }

    return 0;

}

A. The code is erroneous since the subscript for array used in for loop is in the range 1 to size.

B. The code is erroneous since the values of array are getting scanned through the loop.

C. The code is erroneous since the statement declaring array is invalid.

D. The code is correct and runs successfully.

POINTERS

1. What will be the output of the program ?

#include<stdio.h>

int main()

{

    static char *s[] = {"black", "white", "pink", "violet"};

    char **ptr[] = {s+3, s+2, s+1, s}, ***p;

    p = ptr;

    ++p;

    printf("%s", **p+1);

    return 0;

}

A. ink

B. ack

C. ite

D. let

2. What will be the output of the program ?

#include<stdio.h>

int main()

{

    int x=30, *y, *z;

    y=&x; /* Assume address of x is 500 and integer is 4 byte size */

    z=y;

    *y++=*z++;

    x++;

    printf("x=%d, y=%d, z=%d\n", x, y, z);

    return 0;

}

A. x=31, y=502, z=502

B. x=31, y=500, z=500

C. x=31, y=498, z=498

D. x=31, y=504, z=504

3. What will be the output of the program ?

#include<stdio.h>

int main()

{

    char str[20] = "Hello";

    char *const p=str;

    *p='M';

    printf("%s\n", str);

    return 0;

}

A. Mello

B. Hello

C. HMello

D. MHell

4. What will be the output of the program If the integer is 4bytes long?

#include<stdio.h>

int main()

{

    int ***r, **q, *p, i=8;

    p = &i;

    q = &p;

    r = &q;

    printf("%d, %d, %d\n", *p, **q, ***r);

    return 0;

}

A. 8, 8, 8

B. 4000, 4002, 4004

C. 4000, 4004, 4008

D. 4000, 4008, 4016

5. What will be the output of the program?

#include<stdio.h>

int main(){

    int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};

    int *p, *q;

    p = &arr[1][1][1];

    q = (int*) arr;

    printf("%d, %d\n", *p, *q);

    return 0; }

A. 8, 10

B. 10, 2

C. 8, 1

D. Garbage values