Pointers


  1. What will be the output of the following C code?
    #include <stdio.h>
    void main()
    {
    char *str = "PRAYAG";
    char *ptr = str;
    printf("%c %c", *ptr, str[2]);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    P A


  1. What will be the output of the following C code?
    #include <,stdio.h>
    void main()
    {
    char *n= "KRISHANA";
    char *m = n + 3;
    printf("%c %c", *m, n[5]);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    S A



  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    void *ptr1;
    int var[5] = {50, 60, 70, 80, 90};
    ptr1 = &var[3];
    int *ptr2 = &var[4];
    int m = (int*)ptr1 - ptr2;
    printf("%d\n", m);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    -1


  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    void *ptr1;
    int num[5] = {10, 20, 30, 40, 80};
    ptr1 = &num[4];
    int *ptr2 = &num[3];
    int R = ptr1 - ptr2;
    printf("%d\n", R);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Compilation Error

    main.c: In function ‘main’:
    main.c:8:22: error: invalid operands to binary - (have ‘void *’ and ‘int *’)
    int R = ptr1 - ptr2;



  1. What will be the output of the following C code?
    #include <stdio.h>
    int main()
    {
    int *ptr1 = (int *)4;
    int *ptr2 = (int *)6;
    printf("%d", ptr1 + ptr2);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Compilation Error

    main.c: In function ‘main’:
    main.c:6:27: error: invalid operands to binary + (have ‘int *’ and ‘int *’)
    printf("%d", ptr1 + ptr2);