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

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; 

}

This question was previously asked in
RRB JE 2025 CBT 2 Mechanical and Allied Engg Question Paper English (2-Jul-2026) (Shift-1)
The correct answer is

15 15

To determine the output of the given C code, let's go through it step by step:

    #include<stdio.h>

    int main() 
    {
        int x = 10;
        int *p = &x;
        *p = *p + 5;
        printf("%d %d", x, *p);
        return 0;
    }
    
  1. The code starts by including the standard input-output header file <stdio.h>, which is essential for using the printf function.
  2. In the main function, an integer variable x is initialized with the value 10.
  3. An integer pointer p is created and initialized with the address of x using the address-of operator &.
  4. The statement *p = *p + 5; is executed. Here, *p dereferences the pointer, accessing the value of x. Thus, *p + 5 results in 10 + 5 = 15. This value is then assigned back to x through the pointer.
  5. The printf("%d %d", x, *p); function call prints the values of x and *p. Since *p is still pointing to x, both x and *p print the value 15.

Therefore, the output of this code will be 15 15.

Conclusion: The correct answer is 15 15. This confirms that the pointer p successfully modified the value of x to 15, and both x and *p reflect this change.

Was this answer helpful?

Important Questions from Pointer

  1. The following statement in ‘C’
    int (*f())[ ];
    declares
  2. What would be the equivalent pointer expression for referring the array element ar[m][n][o]
  3. 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:
  4. 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.

  5. 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 */

        }

Need Expert Advice?
Test Series
RRB JE img
Railways
RRB JE (CBT 1 + CBT 2) 2026 Mock Test Series
1515 Tests 19 Tests Free
1655 Attempts
4.3(158)
English, Hindi

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