Pointers


  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. Comment on the output of the following C code.
    #include <stdio.h>
    int main()
    {
    char *s = "Interveiw" //Line 1
    char *p = "Mania\n"; //Line 2
    s = p; //Line 3
    printf("%s, %s\n", s, p); //Line 4
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Memory holding “this” loses its reference at line 3



  1. What is the syntax for constant pointer to address (i.e., fixed pointer address)?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    <type> * const <name>


  1. What type of initialization is needed for the segment “p[3] = ‘3’;” to work?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    char p[] = “Interview!”;



  1. What will be the output of the following C code?
    #include <stdio.h>
    int calc(int n, int m)
    {
    return n + m;
    }
    int main()
    {
    int (*calc_ptr)(int, int);
    calc_ptr = calc;
    printf("The Addition of two numbers is: %d", (int)calc_ptr(21, 13));
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    34