C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 10)
10.
What will be the output of the program ?
#include<stdio.h>

int main()
{
    void *vp;
    char ch=74, *cp="JACK";
    int j=65;
    vp=&ch;
    printf("%c", *(char*)vp);
    vp=&j;
    printf("%c", *(int*)vp);
    vp=cp;
    printf("%s", (char*)vp+2);
    return 0;
}
JCK
J65K
JAK
JACK
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
84 comments Page 9 of 9.

Chinni said:   1 decade ago
Thanks a lot... dude.

Ganesh said:   1 decade ago
Thanks Nilesh nice explanation.

Preethi said:   1 decade ago
Thanks Nilesh.

Nilesh said:   1 decade ago
Pointer always store integer value so cp will store the memory address of location where string "jack " is stored.

Step 1 : vp = &ch;
/*Will store address of ch in vp so while we print content in printf it will print asccii value of 74 i.e "J"*/

Step 2 : vp = &j;
/* It will assign address of j to vp again it will print ascii value of 65 as "A"*/

Step 3 : vp = cp;
/* In this step cp is pointing to memory locatioon where string jack is stored and we r incrementing it by two so it will point to "C" from sring "JACK" and since we hava given %S in printf so it will print content from c onwords ie "CK"*/

So final combined output will be JACK.
(47)


Post your comments here:

Your comments will be displayed after verification.