Home » C Programming » Pointers » Question
  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. 80
    2. 40
    3. 30
    4. 20
    5. Compilation Error
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;



Your comments will be displayed only after manual approval.