hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    Consider the following code snippet: What is the output of the above program?
    Question



    Consider the following code snippet:

    What is the output of the above program?

    A.

    F

    B.

    G

    C.

    H

    D.

    J

    E.

    K

    Correct option is D

    The program defines a character array arr[] initialized with the string "FGHJKJGF". The pointer p points to the first element of the array (arr[0]). The expression *(p + 3) accesses the value at the position 3 indices ahead of p (0-based indexing).
    Step-by-Step Execution:
    1. Array Initialization:
    · char arr[] = "FGHJKJGF";
    · The array arr is initialized with the string "FGHJKJGF".
    2. Pointer Initialization:
    · char *p = arr;
    · The pointer p points to the first element of the array arr.
    3. Print Statement:
    · printf("%c\n", *(p + 3));
    · This statement prints the character at the position p + 3.
    · p is pointing to the first element of the array, i.e., arr[0].
    · *(p + 3) accesses the element at index 3 of the array.
    4. Evaluating the Expression:
    · The array arr is indexed as follows:
    · arr[0] = 'F'
    · arr[1] = 'G'
    · arr[2] = 'H'
    · arr[3] = 'J' (This is the 3rd index)
    Therefore, the output of the program is: (d) J
    Important Key Points:
    1. Pointer arithmetic in C allows direct access to elements in an array.
    2. *(p + n) is equivalent to arr[n] when p points to the first element of the array.
    3. String arrays in C are null-terminated (\0), but the null terminator is irrelevant here since it’s not accessed.
    Knowledge Booster:
    · Pointer Basics:
    · *p refers to the value at the memory location pointed to by p.
    · p + n moves the pointer n steps forward (or backward if n is negative) in memory.
    · Array Access:
    · arr[n] is equivalent to *(arr + n) in C.

    Free Tests

    Free
    Must Attempt
    Video Solutions

    RBI Assistant Pre 2026 Full Mock Test -01

    languageIcon English
    • pdpQsnIcon100 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    Free
    Must Attempt
    Video Solutions

    RBI Asst Prelims 2026 : Reasoning Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt
    Video Solutions

    RBI Asst Prelims 2026 : Quant Section Test 01

    languageIcon English
    • pdpQsnIcon35 Questions
    • pdpsheetsIcon35 Marks
    • timerIcon20 Mins
    languageIcon English
    test-prime-package

    Access ‘IBPS SO IT Officer’ Mock Tests with

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