Home » C Programming » Pointers » Question
  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. Garbage value
    2. Compilation Error
    3. Runtime Error
    4. Undefined behaviour
    5. None of these
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;



Your comments will be displayed only after manual approval.