Pointers


  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    char *str = "Interview, Mania\n";
    char *strc = "Welcome to\n";
    strcpy(strc, str);
    printf("%s\n", strc);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Crash/segmentation fault


  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    int arr[5] = {61, 62, 63, 64, 65};
    void *p = &arr[1];
    void *p1 = &arr[5];
    int Res = 0;
    Res = p1 - p;
    printf("%d\n", Res);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    16



  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    int array[3] = {16, 17, 18};
    int *p = &array[1];
    float m = 1;
    p = p + m;
    printf("%d\n", *p);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Compilation Error

    main.c: In function ‘main’:
    main.c:7:15: error: invalid operands to binary + (have ‘int *’ and ‘float’)
    p = p + m;


  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    int num[5] = {15, 25, 35, 45, 55};
    int *ptr1 = &num[3];
    int *ptr2 = &num[4];
    ptr2 = ptr2 * 1;
    printf("%d\n", *ptr2);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Compilation Error

    main.c: In function ‘main’:
    main.c:7:21: error: invalid operands to binary * (have ‘int *’ and ‘int’)
    ptr2 = ptr2 * 1;



  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    int array1[5] = {10, 20, 30, 40, 50};
    int array2[5] = {11, 21, 31, 41, 51};
    int R = &array2[3] - &array1[2];
    printf("%d\n", R);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    -7