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:
- The integer variable
xis declared and initialized with the value0. - A pointer variable
*ptrof type integer is declared and it is assigned the address ofxusing the&operator. - The
printffunction is used to print the value at the address stored in the pointerptr. The*operator is used to dereference the pointer, i.e., to get the value stored at the address it is pointing to. - Since
ptris pointing tox, andxis0, theprintffunction prints0. - So, the output of the program is
0.
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.