What will be the output of the following C code?#include <stdio.h>void main(){int k = 5;int *p = &k;int **m = &p; **m = 6; printf("%d\n", k);}A. 5B. Run time errorC. 6D. Junk
Question
What will be the output of the following C code?#include <stdio.h>void main(){int k = 5;int *p = &k;int **m = &p; **m = 6; printf("%d\n", k);}A. 5B. Run time errorC. 6D. Junk
Solution
The output of the given C code will be 6.
Here's the step by step explanation:
- An integer variable
kis declared and initialized with the value5. - A pointer
pis declared and it is initialized with the address ofk. - A pointer to a pointer
mis declared and it is initialized with the address ofp. - The value at the address pointed to by
m(which is the address pointed to byp, which is the address ofk) is changed to6. This effectively changes the value ofkto6. - The value of
kis printed, which is now6.
So, the correct answer is C. 6.
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;}
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.