Pointers

16

Point out the error in the program

#include<stdio.h>

int main()
{
    int a[] = {10, 20, 30, 40, 50};
    int j;
    for(j=0; j<5; j++)
    {
        printf("%d\n", a);
        a++;
    }
    return 0;
}
A. Error: Declaration syntax
B. Error: Expression syntax
C. Error: LValue required
D. Error: Rvalue required

17

Point out the compile time error in the program given below.

#include<stdio.h>

int main()
{
    int *x;
    *x=100;
    return 0;
}
A. Error: invalid assignment for x
B. Error: suspicious pointer conversion
C. No error
D. None of above

18

If the size of integer is 4bytes, What will be the output of the program?

#include<stdio.h>#define CUBE(x) (x*x*x)

int main()
{
    int arr[] = {12, 13, 14, 15, 16};
    printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
    return 0;
}
A. 10, 2, 4
B. 20, 4, 4
C. 16, 2, 2
D. 20, 2, 2

19

What will be the output of the program ?

#include<stdio.h>

int main()
{
    int i, a[] = {2, 4, 6, 8, 10};
    change(a, 5);
    for(i=0; i<=4; i++)
        printf("%d, ", a[i]);
    return 0;
}
void change(int *b, int n)
{
    int i;
    for(i=0; i 
                                                    
A. 7, 9, 11, 13, 15
B. 2, 15, 6, 8, 10
C. 2 4 6 8 10
D. 3, 1, -1, -3, -5

20

What will be the output of the program ?

#include<stdio.h>
#include<string.h>

int main()
{
    int i, n;
    char *x="Alice";
    n = strlen(x);
    *x = x[n];
    for(i=0; i<=n; i++)
    {
        printf("%s ", x);
        x++;
    }
    printf("\n", x);
    return 0;
}
A. Alice
B. ecilA
C. Alice lice ice ce e
D. lice ice ce e