All Exams Test series for 1 year @ ₹349 only
Question

What will be the output of the following C code?

#include<stdio.h>

void main()

{

    int arr[5] = {10, 20, 30, 40, 50};

    int *p = (int*) (&arr + 1);

    printf("%d%d", *(arr + 1), *(p - 1));

}

This question was previously asked in
UGC NET 2024 Management Question Paper (02-Sep-2024) (Shift 2)
The correct answer is

20 50

In C, arr used in an expression decays to a pointer to its first element (type int *), while &arr is a pointer to the whole array (type int (*)[5]). Adding 1 to a pointer moves it by the size of the type it points to, so &arr + 1 jumps past all five integers.

Step 1 — *(arr + 1) is the same as arr[1], which is 20.

Step 2 — &arr + 1 points just beyond arr[4] (5 × sizeof(int) bytes ahead). Casting it to int * stores that address in p.

Step 3 — p - 1 now steps back by one int, landing on arr[4], so *(p - 1) is 50.

Step 4 — The printf therefore prints 20 followed by 50.

The pair 10 50 would need arr[0] as the first value, but *(arr + 1) reads index 1. The pairs 30 40 and 20 40 would hold only if &arr + 1 advanced by a single element instead of the whole array, which is not how pointer-to-array arithmetic works.

20 50 option is correct.

Was this answer helpful?

Similar Questions

  1. What is the output of the following program ?

    (Assume that the appropriate preprocessor directives are included and there is no syntax error)

    main ( )

        {    char S[ ]="ABCDEFGH";

                printf ("%C", * (& S[3]));

                printf ("%s", S+4);

                printf ("%u", S);

        /* Base address of S is 1000 */

        }

  2. Which of the following statements about pointers in C are TRUE.

    (A) Pointers can be used to access array elements

    (B) Pointers can store the address of another pointer

    (C) Pointers are automatically deferenced in expression

    (D) Pointers cannot be used to access structure members

    Choose the correct answer from the options given below :

  3. Which of the following is correct way to declare a functional pointer in C ?

  4. 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 ?

  5. Consider the following code :

    #include<stdio.h>

    void f1(char *x, char *y) {

        char *t1; t1=x; x=y; y=t1;}

    void f2(char **x, char **y) {

        char *t1; t1=*x; *x=*y; *y=t1;}

    int main()

    {

        char *a="ONE", *b="TWO";

        f1(a, b); printf("%s %s", a, b);

        f2(&a, &b); printf("%s %s", a, b);

        return 0;

    }

    What will be the output of the above code?

  6. #include<stdio.h>

    void main()

    {

        int arr[]={1, 2, 3, 4, 5};

        int *p=arr;

        printf("%d", *p++);

        printf("%d", *(p+1));

    }

    Find the output of the above code?

  7. What does the following expression means ?

    char *(*(* a[N]) ( )) ( );


Important Questions from Pointer

  1. What is the output of the following C programming language code? 

    #include<stdio.h>

     int main()

    { 

    int x = 10;

     int *p = &x;

     *p = *p + 5;

     printf("%d %d", x, *p); 

    return 0; 

    }

  2. The following statement in ‘C’
    int (*f())[ ];
    declares
  3. What would be the equivalent pointer expression for referring the array element ar[m][n][o]
  4. Only legal pointer operations:
    A. pointer + number $\rightarrow$ pointer
    B. pointer - number $\rightarrow$ number
    C. pointer + pointer $\rightarrow$ pointer
    D. pointer - pointer $\rightarrow$ pointer
    E. pointer - pointer $\rightarrow$ number
    Choose the most appropriate answer from the options given below:
  5. Consider the following ANSI-C program.

    #include <stdio.h>
    int main(){
     int *ptr, a, b, c;
     a=5; b=11; c=20;
     ptr=&a; *ptr=c; ptr=&c;
     a=*(&b); c=*ptr-a;
     printf("%d",c);
     return(0);
    }

    The output of this program is ____________. (answer in integer)

    Note: Assume that the program compiles and runs successfully.

Need Expert Advice?
Upcoming Exams
CTET
December 12, 2026
Test Series
UGC NET img
Teaching
UGC NET (Paper 2) 2026 Mock Test Series
796 Tests 2 Tests Free
4.4(39)
English
More Questions from UGC NET

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App