Knowee
Questions
Features
Study Tools

What will be the output of the following C code? #include <stdio.h> void main() { int x = 0; int *ptr = &x; printf("%d\n", *ptr); }

Question

What will be the output of the following C code? #include <stdio.h> void main() { int x = 0; int *ptr = &x; printf("%d\n", *ptr); }

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given C code will be "0".

Here's the step by step explanation:

  1. The integer variable x is declared and initialized with the value 0.
  2. A pointer variable *ptr of type integer is declared and it is assigned the address of x using the & operator.
  3. The printf function is used to print the value at the address stored in the pointer ptr. The * operator is used to dereference the pointer, i.e., to get the value stored at the address it is pointing to.
  4. Since ptr is pointing to x, and x is 0, the printf function prints 0.
  5. So, the output of the program is 0.

This problem has been solved

Similar Questions

what will be the output of the c program?

What will be the output of the following code?

What will be the output of the following C++ code?

What will be the output of the following program?

What will be the output of the following C code?#include <stdio.h>int main() {    int i;    for (i = 0; i < 5; i++);    printf("%d\n", i);    return 0;}

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.