A

Admin • 833K Points
Coach

Q. What will be the output of the following C code?

Code:
#include <stdio.h>
int main(){
int x = 10, *ptr;
ptr = &x;
*ptr = 20;
printf("%d", x);
}
  • (A) 10
  • (B) 20
  • (C) Error
  • (D) A garbage value
  • Correct Answer - Option(B)
  • Views: 18
  • Filed under category C Programming
  • Hashtags:

Explanation by: Admin

In the above program, x contains 10 and ptr is a pointer to x. We are changing the value of x with the help of pointer. Thus, the value will be changed and it will be 20.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.