hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    Consider following C program: #include <stdio.h> int main() { int x[] = {2, 4, 6, 8, 10}; int a, b = 0, *y = x + 4; for (a
    Question



    Consider following C program:
    #include <stdio.h>
    int main()
    {
    int x[] = {2, 4, 6, 8, 10};
    int a, b = 0, *y = x + 4;
    for (a = 0; a < 5; a++)
    {
    b = b + (*y - a) - *(y - a);
    }
    printf("%d\n", b);
    return 0;
    }
    What will be the output of the above C program?

    A.

    4

    B.

    6

    C.

    8

    D.

    10

    Correct option is D


    1. The pointer y points to x + 4, which is x[4] (value 10).
    2. In each iteration, the expression (*y - a) - *(y - a) is evaluated.
    · a = 0: b = b + (10 - 0) - 10 = 0
    · a = 1: b = b + (10 - 1) - 8 = 1
    · This results in b = 10 after the loop.
    Information Booster:
    Pointers: Useful for accessing and manipulating elements of an array efficiently.

    Free Tests

    Free
    Must Attempt

    Basics of Education: Pedagogy, Andragogy, and Hutagogy

    languageIcon English
    • pdpQsnIcon10 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon12 Mins
    languageIcon English
    Free
    Must Attempt

    UGC NET Paper 1 Mock Test 1

    languageIcon English
    • pdpQsnIcon50 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    Free
    Must Attempt

    Basics of Education: Pedagogy, Andragogy, and Hutagogy

    languageIcon English
    • pdpQsnIcon10 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon12 Mins
    languageIcon English

    Similar Questions

    test-prime-package

    Access ‘UGC NET Computer Science’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    446k+ students have already unlocked exclusive benefits with Test Prime!

    Similar Questions

    Our Plans
    Monthsup-arrow